00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00032 #ifndef _ols_sockets_header_
00033 #define _ols_sockets_header_
00034
00035
00036 #ifdef _WIN32
00037 #include <Winsock2.h>
00038 #else
00039 #include <sys/select.h>
00040 #include <sys/socket.h>
00041 #include <netinet/in.h>
00042 #include <arpa/inet.h>
00043 #include <sys/time.h>
00044 #include <sys/types.h>
00045 #include <netdb.h>
00046 #endif //_WIN32
00047
00048
00049 #define MAX_PENDING_CONNECTIONS 44
00050 #define MAX_EMPTY_READINGS 4
00051
00052
00053
00054
00055
00056
00057 #ifdef _WIN32
00058 typedef SOCKET hsocket;
00059 typedef struct sockaddr_in hsockaddr;
00060 typedef unsigned short hport;
00061 typedef struct in_addr hip;
00062
00063 typedef struct _sockets_env {
00064 WSADATA wsaData;
00065 } sockets_env;
00066
00067 #else //i.e. LINUX
00068 typedef int hsocket;
00069 typedef struct sockaddr_in hsockaddr;
00070 typedef unsigned short hport;
00071 typedef struct in_addr hip;
00072
00073 typedef struct _sockets_env {
00074 } sockets_env;
00075 #endif //_WIN32
00076
00077
00081 typedef struct _four_bytes {
00082 unsigned char b1;
00083 unsigned char b2;
00084 unsigned char b3;
00085 unsigned char b4;
00086 } four_bytes;
00087
00088 typedef union {
00089 hip ip_num;
00090 four_bytes ip_bytes;
00091 } ip_to_bytes;
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 extern sockets_env sockets_os_enviroment;
00105
00106
00107
00108 #ifdef __cplusplus
00109 extern "C"
00110 {
00111 #endif
00112
00113
00114
00115
00116
00117
00118
00119
00123 int init_socket_subsystem();
00124
00128 int cleanup_socket_subsystem();
00129
00132 int common_send(hsocket sk,
00133 const char *buf,
00134 unsigned int buflen,
00135 unsigned int *sent);
00136
00137 int common_recv(hsocket sk,
00138 char *buf,
00139 unsigned int buflen,
00140 unsigned int *received);
00141
00142
00155 int nonblocking_send(hsocket sk,
00156 unsigned int ms_to_wait,
00157 const char *buf,
00158 unsigned int buflen,
00159 unsigned int *sent);
00160
00161
00162
00163
00176 int nonblocking_recv(hsocket sk,
00177 unsigned int ms_to_wait,
00178 char *buf,
00179 unsigned int buflen,
00180 unsigned int *received);
00181
00182
00183
00184
00198 int nonblocking_accept(hsocket server_socket,
00199 unsigned int ms_to_wait,
00200 hsocket *new_socket,
00201 hsockaddr *peer_address);
00202
00203
00204
00214 int ip_to_str(hip ip, char *buffer);
00215
00216
00217
00223
00224
00225 int _str_to_ip(const char *buffer, hip *pip);
00226
00227
00228
00236 int create_listening_socket(hsocket *phsocket, struct in_addr server_address, hport server_port);
00237
00238
00242 int connect_socket(hsocket sock, const hsockaddr *paddr);
00243
00244
00245
00249 void close_socket(hsocket sock);
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00261 int send_socket(hsocket sock, const char *buff, unsigned int len);
00262
00264 int receive_socket(hsocket sock, char *recvbuff, unsigned int bufflen);
00265
00267 hsocket accept_socket(hsocket server_socket, hsockaddr *peer_address);
00268
00269
00270
00271
00272
00273 hsocket new_tcp_socket();
00274
00275 int listen_socket(hsocket sock);
00276 int bind_socket(hsocket sock, struct in_addr ip, hport port);
00277
00278
00279 #ifdef __cplusplus
00280 }
00281 #endif
00282
00283
00284 #endif //_ols_sockets_header_