abyss_socket.h

Go to the documentation of this file.
00001 #ifndef SOCKET_H_INCLUDED
00002 #define SOCKET_H_INCLUDED
00003 
00004 #include <netinet/in.h>
00005 
00006 #include <xmlrpc-c/abyss.h>
00007 
00008 #include <netinet/in.h>
00009 
00010 #define IPB1(x) (((unsigned char *)(&x))[0])
00011 #define IPB2(x) (((unsigned char *)(&x))[1])
00012 #define IPB3(x) (((unsigned char *)(&x))[2])
00013 #define IPB4(x) (((unsigned char *)(&x))[3])
00014 
00015 typedef struct in_addr TIPAddr;
00016 
00017 typedef void SocketDestroyImpl(TSocket * const socketP);
00018 
00019 typedef void SocketWriteImpl(TSocket *             const socketP,
00020                              const unsigned char * const buffer,
00021                              uint32_t              const len,
00022                              abyss_bool *          const failedP);
00023 
00024 typedef uint32_t SocketReadImpl(TSocket * const socketP,
00025                                 char *    const buffer,
00026                                 uint32_t  const len);
00027 
00028 typedef abyss_bool SocketConnectImpl(TSocket * const socketP,
00029                                      TIPAddr * const addrP,
00030                                      uint16_t  const portNumber);
00031 
00032 typedef abyss_bool SocketBindImpl(TSocket * const socketP,
00033                                   TIPAddr * const addrP,
00034                                   uint16_t  const portNumber);
00035 
00036 typedef abyss_bool SocketListenImpl(TSocket * const socketP,
00037                                     uint32_t  const backlog);
00038 
00039 typedef void SocketAcceptImpl(TSocket *    const listenSocketP,
00040                               abyss_bool * const connectedP,
00041                               abyss_bool * const failedP,
00042                               TSocket **   const acceptedSocketPP,
00043                               TIPAddr *    const ipAddrP);
00044 
00045 typedef uint32_t SocketErrorImpl(TSocket * const socketP);
00046 
00047 typedef uint32_t SocketWaitImpl(TSocket *  const socketP,
00048                                 abyss_bool const rd,
00049                                 abyss_bool const wr,
00050                                 uint32_t   const timems);
00051 
00052 typedef uint32_t SocketAvailableReadBytesImpl(TSocket * const socketP);
00053 
00054 typedef void SocketGetPeerNameImpl(TSocket *    const socketP,
00055                                    TIPAddr *    const ipAddrP,
00056                                    uint16_t *   const portNumberP,
00057                                    abyss_bool * const successP);
00058 
00059 struct TSocketVtbl {
00060     SocketDestroyImpl            * destroy;
00061     SocketWriteImpl              * write;
00062     SocketReadImpl               * read;
00063     SocketConnectImpl            * connect;
00064     SocketBindImpl               * bind;
00065     SocketListenImpl             * listen;
00066     SocketAcceptImpl             * accept;
00067     SocketErrorImpl              * error;
00068     SocketWaitImpl               * wait;
00069     SocketAvailableReadBytesImpl * availableReadBytes;
00070     SocketGetPeerNameImpl        * getPeerName;
00071 };
00072 
00073 struct _TSocket {
00074     uint               signature;
00075         /* With both background and foreground use of sockets, and
00076            background being both fork and pthread, it is very easy to
00077            screw up socket lifetime and try to destroy twice.  We use
00078            this signature to help catch such bugs.
00079         */
00080     void *             implP;
00081     struct TSocketVtbl vtbl;
00082 };
00083 
00084 #define TIME_INFINITE   0xffffffff
00085 
00086 extern abyss_bool SocketTraceIsActive;
00087 
00088 abyss_bool
00089 SocketInit(void);
00090 
00091 void
00092 SocketTerm(void);
00093 
00094 void
00095 SocketCreate(const struct TSocketVtbl * const vtblP,
00096              void *                     const implP,
00097              TSocket **                 const socketPP);
00098 
00099 void
00100 SocketWrite(TSocket *             const socketP,
00101             const unsigned char * const buffer,
00102             uint32_t              const len,
00103             abyss_bool *          const failedP);
00104 
00105 uint32_t
00106 SocketRead(TSocket *       const socketP, 
00107            unsigned char * const buffer, 
00108            uint32_t        const len);
00109 
00110 abyss_bool
00111 SocketConnect(TSocket * const socketP,
00112               TIPAddr * const addrP,
00113               uint16_t  const portNumber);
00114 
00115 abyss_bool
00116 SocketBind(TSocket * const socketP,
00117            TIPAddr * const addrP,
00118            uint16_t  const portNumber);
00119 
00120 abyss_bool
00121 SocketListen(TSocket * const socketP,
00122              uint32_t  const backlog);
00123 
00124 void
00125 SocketAccept(TSocket *    const listenSocketP,
00126              abyss_bool * const connectedP,
00127              abyss_bool * const failedP,
00128              TSocket **   const acceptedSocketP,
00129              TIPAddr *    const ipAddrP);
00130 
00131 uint32_t
00132 SocketWait(TSocket *  const socketP,
00133            abyss_bool const rd,
00134            abyss_bool const wr,
00135            uint32_t   const timems);
00136 
00137 uint32_t
00138 SocketAvailableReadBytes(TSocket * const socketP);
00139 
00140 void
00141 SocketGetPeerName(TSocket *    const socketP,
00142                   TIPAddr *    const ipAddrP,
00143                   uint16_t *   const portNumberP,
00144                   abyss_bool * const successP);
00145 
00146 uint32_t
00147 SocketError(TSocket * const socketP);
00148 
00149 #endif

Generated on Thu May 17 10:00:23 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6