Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

sockets.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *
00003  * Verball Model Storage Library, Common Information Model Library 
00004  * for integration of Intelligent Services.
00005  * Copyright (C) 2005 Nikita Vinokurov, Orgway LLC.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; 
00010  * version 2.1 of the License.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00020  * Boston, MA  02110-1301  USA
00021  *
00022  * $Id: sockets.h,v 1.10 2006/09/18 21:38:30 sbreg Exp $
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  * Typedefs
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  * Defenitions
00096  *
00097  */
00098 
00099 
00100 /*
00101  * Data structures
00102  *
00103  */
00104 extern sockets_env sockets_os_enviroment;
00105 
00106 
00107 
00108 #ifdef __cplusplus
00109 extern "C"
00110 {
00111 #endif/* __cplusplus */
00112 
00113 
00114 /*
00115  * Functions
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 //int str_to_ip(const char *buffer, hip *pip);
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 /* Internal functions 
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 /* new_tcp_socket
00270  * Creates new socket
00271  * Returns -1 on error, otherwise - new socket
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/* __cplusplus */
00282 
00283 
00284 #endif //_ols_sockets_header_

Generated on Wed Dec 27 16:52:18 2006 for VRB Online Server by  doxygen 1.4.4