liblogging: sockets.h Source File

Main Page | Compound List | File List | Compound Members | File Members | Related Pages

# sockets.h

Go to the documentation of this file.

    00001
    00050 #ifndef __LIB3195_SOCKETS_H_INCLUDED__
    00051 #define __LIB3195_SOCKETS_H_INCLUDED__ 1
    00052
    00053 #include "config.h"
    00054 #ifdef SROS_WIN32
    00055 #  include <winsock2.h>
    00056 #else
    00057 #include <sys/types.h>
    00058 #include <sys/time.h>
    00059 #include <sys/socket.h>
    00060 #include <sys/select.h>
    00061 #include <unistd.h>
    00062 #include <netinet/in.h>
    00063 #include <netdb.h>
    00064 #include <errno.h>
    00065 #endif
    00066
    00067 #define sbSockCHECKVALIDOBJECT(x) {assert(x != NULL); assert(x->OID == OIDsbSock);}
    00068
    00072 #define sbSOCK_NO_CHAR -1
    00073
    00074 struct sbSockObject
    00078 {
    00079         srObjID OID;
    00080         srRetVal iLastErr;
    00081         SR_SOCKET sock;
    00082         int bIsInError;
    00083         int     dwLastError;
    00084         char szInBuf[SOCKETMAXINBUFSIZE];
    00085         int iCurInBufPos;
    00086         int iInBufLen;
    00087         fd_set fdset;
    00088 #       if FEATURE_LISTENER == 1
    00089         struct sockaddr_in RemoteHostAddr;
    00090         char *pRemoteHostIP;
    00091         int iRemHostIPBufLen;
    00092 #       endif
    00093 };
    00094 typedef struct sbSockObject sbSockObj;
    00095
    00096
    00097 /* The following three macros could also be inline code.
    00098  * For now, I have kept them to be macros to make
    00099  * facilitate porting.
    00100  */
    00101
    00103 #define sbSockGetLastError(pThis) pThis->iLastErr
    00104
    00106 #define sbSockSetLastError(pThis, iRet) pThis->iLastErr = iRet
    00107
    00109 #define sbSockResetLastError(pThis) pThis->iLastErr = SR_RET_OK
    00110
    00111
    00123 srRetVal sbSockLayerInit(int bInitOSStack);
    00134 srRetVal sbSockLayerExit(int bExitOSStack);
    00135
    00136 sbSockObj* sbSockInit(void);
    00137 sbSockObj* sbSockInitEx(int af, int iSockType);
    00139 srRetVal sbSockExit(sbSockObj*);
    00140 int sbSockGetLastSockError(sbSockObj*);
    00146 srRetVal sbSockConnectoToHost(sbSockObj* pThis, char* pszHost, int iPort);
    00147
    00154 int sbSockHasReceiveData(sbSockObj* pThis);
    00155
    00164 int sbSockReceive(sbSockObj* pThis, char * pszBuf, int iLen);
    00165
    00173 int sbSockSend(sbSockObj* pThis, const char* pszBuf, int iLen);
    00174
    00183 int sbSockGetRcvChar(sbSockObj *pThis);
    00184
    00193 int sbSockPeekRcvChar(sbSockObj *pThis);
    00194
    00198 srRetVal sbSockClosesocket(sbSockObj *pThis);
    00199
    00200
    00205 srRetVal sbSockWaitReceiveData(struct sbSockObject* pThis);
    00206
    00210 typedef fd_set srSock_fd_set;
    00211
    00218 #define sbSockFD_ZERO(fdset) FD_ZERO(fdset)
    00219
    00225 #define sbSockFD_SET(sock, fdset) FD_SET(sock, fdset)
    00226
    00232 #define sbSockFD_ISSET(sock, fdset) FD_ISSET(sock, fdset)
    00233
    00234
    00244 #       ifdef SROS_WIN32
    00245                 int sbSockSelectMulti(srSock_fd_set *fdsetRD, srSock_fd_set *fdsetWR, int iTimOutSecs, int iTimOutMSecs);
    00246 #       else
    00247                 int sbSockSelectMulti(srSock_fd_set *fdsetRD, srSock_fd_set *fdsetWR, int iTimOutSecs, int iTimOutMSecs, int iHighestDesc);
    00248 #       endif
    00249
    00253 srRetVal sbSockListen(sbSockObj*pThis);
    00254
    00276 sbSockObj*      sbSockInitListenSock(srRetVal *iRet, int iType, char *szBindToAddress, unsigned uBindToPort);
    00277
    00282 srRetVal sbSockAcceptConnection(sbSockObj* pThis, sbSockObj** pNew);
    00283
    00287 srRetVal sbSockSetNonblocking(sbSockObj*pThis);
    00288
    00293 srRetVal sbSockGetRemoteHostIP(sbSockObj *pThis, char **ppszHost);
    00294
    00304 srRetVal sbSock_gethostname(char **psz);
    00305
    00325 srRetVal sbSockGetIPusedForSending(sbSockObj* pThis, char**ppsz);
    00326
    00327
    00338 srRetVal sbSockRecvFrom(sbSockObj *pThis, char* pRecvBuf, int *piBufLen, char** ppFrom);
    00339
    00340
    00341 #ifdef SROS_WIN32
    00342 #       define SBSOCK_EWOULDBLOCK WSAEWOULDBLOCK
    00343 #else
    00344 #       define SBSOCK_EWOULDBLOCK EWOULDBLOCK
    00345 #       define SOCKET_ERROR -1
    00346 #endif
    00347
    00348 #endif