00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __LSCP_SOCKET_H
00024 #define __LSCP_SOCKET_H
00025
00026 #include "lscp/thread.h"
00027
00028 #if defined(WIN32)
00029 #include <winsock.h>
00030 #else
00031 #include <unistd.h>
00032 #include <sys/socket.h>
00033 #include <netinet/in.h>
00034 #include <netinet/tcp.h>
00035 #include <arpa/inet.h>
00036 #include <netdb.h>
00037 #endif
00038
00039 #if defined(__cplusplus)
00040 extern "C" {
00041 #endif
00042
00043
00044
00045
00046 #if defined(WIN32)
00047 typedef SOCKET lscp_socket_t;
00048 typedef int socklen_t;
00049 #else
00050 typedef int lscp_socket_t;
00051 #define INVALID_SOCKET -1
00052 #define SOCKET_ERROR -1
00053 #define closesocket(s) close(s)
00054 #endif
00055
00056 #define LSCP_BUFSIZ 1024
00057
00058 void lscp_socket_perror (const char *pszPrefix);
00059 void lscp_socket_herror (const char *pszPrefix);
00060
00061 void lscp_socket_getopts (const char *pszPrefix, lscp_socket_t sock);
00062 void lscp_socket_trace (const char *pszPrefix, struct sockaddr_in *pAddr, const char *pchBuffer, int cchBuffer);
00063
00064
00065
00066
00067
00068 typedef struct _lscp_socket_agent_t {
00069
00070 lscp_socket_t sock;
00071 struct sockaddr_in addr;
00072 lscp_thread_t *pThread;
00073 int iState;
00074
00075 } lscp_socket_agent_t;
00076
00077 void lscp_socket_agent_init (lscp_socket_agent_t *pAgent, lscp_socket_t sock, struct sockaddr_in *pAddr, int cAddr);
00078 lscp_status_t lscp_socket_agent_start (lscp_socket_agent_t *pAgent, lscp_thread_proc_t pfnProc, void *pvData, int iDetach);
00079 lscp_status_t lscp_socket_agent_join (lscp_socket_agent_t *pAgent);
00080 lscp_status_t lscp_socket_agent_free (lscp_socket_agent_t *pAgent);
00081
00082 #if defined(__cplusplus)
00083 }
00084 #endif
00085
00086
00087 #endif // __LSCP_SOCKET_H
00088
00089