Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_SocketSCTP.hpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 #ifndef _SCTP_SOCKET_
00020 #define _SCTP_SOCKET_
00021 
00022 #include "list_t.hpp"
00023 #include "map_t.hpp"
00024 
00025 #include "S_SCTPIpAddr.hpp"
00026 #include <netinet/tcp.h>
00027 #include <netdb.h>
00028 
00029 #include "C_Transport.hpp"
00030 #include "C_TransportEvent.hpp"
00031 #include "C_SCTPDataDecode.hpp"
00032 #include "C_ProtocolBinaryFrame.hpp"
00033 
00034 #include "ReceiveMsgContext.h"
00035 
00036 typedef enum _enum_socket_mode {
00037   E_SOCKET_TCP_MODE,
00038   E_SOCKET_UDP_MODE
00039 } T_SocketType, *T_pSocketType ;
00040 
00041 typedef struct _data_rcv {
00042   size_t         m_size ;
00043   struct timeval m_time ;
00044   unsigned char *m_data ;
00045 } T_DataRcv, *T_pDataRcv ;
00046 
00047 typedef enum _socket_state {
00048   E_SOCKET_STATE_NOT_READY = 0,
00049   E_SOCKET_STATE_INPROGESS,
00050   E_SOCKET_STATE_READY
00051 } T_SocketState, *T_pSocketState ;
00052 
00053 typedef list_t<T_pDataRcv> T_DataRcvList, *T_pDataRcvList ;
00054 
00055 class C_SocketSCTP {
00056 public:
00057    C_SocketSCTP (int P_channel_id) ;
00058    C_SocketSCTP (T_SocketType P_type, int P_port, int P_channel_id);
00059    C_SocketSCTP (T_SocketType P_type, int P_channel_id);
00060 
00061    int _open (int    P_socket_domain, 
00062               size_t P_buffer_size,
00063               C_ProtocolBinaryFrame *P_protocol);
00064 
00065   virtual ~C_SocketSCTP () ;
00066   virtual size_t received_buffer (unsigned char  *P_data, 
00067                                   size_t          P_size_buf,
00068                                   struct timeval *P_time) = 0 ;
00069   int     get_id () ;
00070   int     get_channel_id();
00071   void    _close () ;
00072   void    set_fd_set (fd_set *P_rSet, fd_set *P_wSet);
00073   virtual C_SocketSCTP* process_fd_set(fd_set           *P_rSet, 
00074                                        fd_set           *P_wSet,
00075                                        C_TransportEvent *P_event) = 0 ;
00076   void    set_channel_id(int P_channel_id);
00077   void    set_properties () ;
00078   C_pSCTPDataDecode      get_decode () ;
00079   C_ProtocolBinaryFrame* get_protocol() ;
00080   T_pRcvMsgCtxtList      get_list() ;
00081 
00082 protected:
00083 
00084   int                 m_socket_id ; 
00085   int                 m_channel_id ;
00086   T_SocketType        m_type ;
00087   int                 m_src_port ;
00088   T_SocketState       m_state    ;
00089   size_t              m_buffer_size ;
00090 
00091   // decode process temporary
00092   C_ProtocolBinaryFrame  *m_protocol ;
00093   C_pSCTPDataDecode       m_decode   ;
00094 
00095   T_pRcvMsgCtxtList       m_recv_msg_list ;
00096   
00097   size_t  m_recv_buflen ;
00098   char   *m_recv_buf ;
00099   
00100 
00101 } ;
00102 
00103 class C_SocketSCTPWithData : public C_SocketSCTP {
00104 
00105 public:
00106 
00107   C_SocketSCTPWithData(int P_channel_id);
00108   C_SocketSCTPWithData(T_SocketType P_type, 
00109                        T_pIpAddr P_addr, 
00110                        int P_channel_id) ;
00111   virtual ~C_SocketSCTPWithData() ;
00112   C_SocketSCTP* process_fd_set(fd_set *P_rSet, fd_set *P_wSet, 
00113                                C_TransportEvent *P_event) ;
00114   size_t received_buffer (unsigned char  *P_data, 
00115                           size_t          P_size_buf,
00116                           struct timeval *P_time) ;
00117   
00118 protected:
00119 
00120   T_DataRcvList           m_data_queue ;
00121   T_pIpAddr               m_remote_addr_info ;
00122   T_SockAddrStorage       m_accepted_addr ;
00123 
00124   bool                    m_data_recv ;
00125 
00126   void                sctp_event_handler (C_TransportEvent *P_event) ;
00127   bool                sctp_recv_msg (struct msghdr *msg, 
00128                                      ssize_t *nrp, size_t cmsglen);
00129   void                sctp_dispatch_msg (C_TransportEvent *P_event) ;
00130 
00131 
00132 } ;
00133 
00134 class C_SocketSCTPListen : public C_SocketSCTP {
00135 
00136 public:
00137 
00138              C_SocketSCTPListen(T_SocketType  P_type, 
00139                                 T_pIpAddr     P_addr, 
00140                                 int           P_channel_id) ;
00141   virtual   ~C_SocketSCTPListen() ;
00142   int       _open (size_t P_buffer_size, C_ProtocolBinaryFrame *P_protocol);
00143   C_SocketSCTP* process_fd_set(fd_set           *P_rSet, 
00144                                fd_set           *P_wSet,
00145                                C_TransportEvent *P_event) ;
00146   size_t received_buffer (unsigned char  *P_data, 
00147                           size_t          P_size_buf,
00148                           struct timeval *P_time) ;
00149   T_SockAddrStorage * get_source_address () ;
00150   
00151 protected:
00152   
00153   T_pIpAddr           m_source_addr_info ;
00154 
00155 } ;
00156 
00157 class C_SocketSCTPServer : public C_SocketSCTPWithData {
00158 
00159 public:
00160            C_SocketSCTPServer(C_SocketSCTPListen *P_listen, 
00161                               int                 P_channel_id);
00162   virtual ~C_SocketSCTPServer();
00163   int     _open (size_t P_buffer_size, C_ProtocolBinaryFrame *P_protocol) ;
00164 
00165 private:
00166   C_SocketSCTPListen *m_listen_sock ;
00167 
00168 } ;
00169 
00170 
00171 class C_SocketSCTPClient : public C_SocketSCTPWithData {
00172 public:
00173   C_SocketSCTPClient(T_SocketType  P_type, 
00174                      T_pIpAddr     P_addr, 
00175                      int           P_channel_id) ;
00176   virtual ~C_SocketSCTPClient() ;
00177   int _open (T_pOpenStatus P_status,
00178              size_t        P_buffer_size,
00179              C_ProtocolBinaryFrame *P_protocol);
00180 } ;
00181 
00182 typedef map_t<int, C_SocketSCTP*> T_SocketMap, *T_pSocketMap ;
00183 
00184 #endif // _SCTP_SOCKET_

Generated on Wed Mar 7 14:44:58 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002