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

sockets.h File Reference

sockets.h is very difficult for inclusion on WIN32. More...

#include <sys/select.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/types.h>
#include <netdb.h>

Include dependency graph for sockets.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _four_bytes
 These structures are used for represent ip address as bytes. More...
struct  _sockets_env
union  ip_to_bytes

Defines

#define MAX_EMPTY_READINGS   4
#define MAX_PENDING_CONNECTIONS   44

Typedefs

typedef _four_bytes four_bytes
 These structures are used for represent ip address as bytes.
typedef in_addr hip
typedef unsigned short hport
typedef sockaddr_in hsockaddr
typedef int hsocket
typedef _sockets_env sockets_env

Functions

int _str_to_ip (const char *buffer, hip *pip)
 Coverts string to ip address.
hsocket accept_socket (hsocket server_socket, hsockaddr *peer_address)
 Simple wrapper for accept function.
int bind_socket (hsocket sock, struct in_addr ip, hport port)
int cleanup_socket_subsystem ()
 Cleans up socket subsistem.
void close_socket (hsocket sock)
 Closes socket.
int common_recv (hsocket sk, char *buf, unsigned int buflen, unsigned int *received)
int common_send (hsocket sk, const char *buf, unsigned int buflen, unsigned int *sent)
 Send buffer.
int connect_socket (hsocket sock, const hsockaddr *paddr)
 Blocking connect.
int create_listening_socket (hsocket *phsocket, struct in_addr server_address, hport server_port)
 Creates socket for server.
int init_socket_subsystem ()
 Initializes socket subsistem.
int ip_to_str (hip ip, char *buffer)
 Convers ip address to string.
int listen_socket (hsocket sock)
hsocket new_tcp_socket ()
int nonblocking_accept (hsocket server_socket, unsigned int ms_to_wait, hsocket *new_socket, hsockaddr *peer_address)
 Accepts incoming connection like classic "accept" but returns through "ms_to_wait" microseconds, i.e.
int nonblocking_recv (hsocket sk, unsigned int ms_to_wait, char *buf, unsigned int buflen, unsigned int *received)
 Receives incoming data like classic "recv" but returns through "ms_to_wait" microseconds, i.e.
int nonblocking_send (hsocket sk, unsigned int ms_to_wait, const char *buf, unsigned int buflen, unsigned int *sent)
 Sends data like classic "send" but returns through "ms_to_wait" microseconds, i.e.
int receive_socket (hsocket sock, char *recvbuff, unsigned int bufflen)
 Simple wrapper for recv function.
int send_socket (hsocket sock, const char *buff, unsigned int len)
 Simple wrapper for send function.

Variables

sockets_env sockets_os_enviroment


Detailed Description

sockets.h is very difficult for inclusion on WIN32.

Set it at the first place before any inclusion of <windows.h>.


Define Documentation

#define MAX_EMPTY_READINGS   4
 

#define MAX_PENDING_CONNECTIONS   44
 


Typedef Documentation

typedef struct _four_bytes four_bytes
 

These structures are used for represent ip address as bytes.

Must be redefined for architectures, other than x86.

typedef struct in_addr hip
 

typedef unsigned short hport
 

typedef struct sockaddr_in hsockaddr
 

typedef int hsocket
 

typedef struct _sockets_env sockets_env
 


Function Documentation

int _str_to_ip const char *  buffer,
hip pip
 

Coverts string to ip address.

[in] buffer - any address (ip or dns name) [out] pip - pointer to ip address of host (network order) Return 0 if success, otherwise - error code

hsocket accept_socket hsocket  server_socket,
hsockaddr peer_address
 

Simple wrapper for accept function.

Not used.

int bind_socket hsocket  sock,
struct in_addr  ip,
hport  port
 

int cleanup_socket_subsystem  ) 
 

Cleans up socket subsistem.

Needed only for win32

void close_socket hsocket  sock  ) 
 

Closes socket.

  • sock [in] - socket descriptor for closing

int common_recv hsocket  sk,
char *  buf,
unsigned int  buflen,
unsigned int *  received
 

int common_send hsocket  sk,
const char *  buf,
unsigned int  buflen,
unsigned int *  sent
 

Send buffer.

int connect_socket hsocket  sock,
const hsockaddr paddr
 

Blocking connect.

Very simple wrapper of 'connect' function, namelen set to sizeof(hsockaddr)

int create_listening_socket hsocket phsocket,
struct in_addr  server_address,
hport  server_port
 

Creates socket for server.

  • phsocket [out] - new socket descriptor
  • server_address [in] - ip address of interface
  • server_port [in] - server port Returns new socket with incomming connection on success, -1 on error.

int init_socket_subsystem  ) 
 

Initializes socket subsistem.

May be used only in Win32

int ip_to_str hip  ip,
char *  buffer
 

Convers ip address to string.

Use this function instead of inet_ntoa in multithreaded solutions. [in] ip address in network byte order [out] string will filled with text view of ip (as '127.0.0.1') Function do not control buffer length - be aware! Buffer length must be at least 22 bytes. Returns length of filled data (<0 || 0 - error)

int listen_socket hsocket  sock  ) 
 

hsocket new_tcp_socket  ) 
 

int nonblocking_accept hsocket  server_socket,
unsigned int  ms_to_wait,
hsocket new_socket,
hsockaddr peer_address
 

Accepts incoming connection like classic "accept" but returns through "ms_to_wait" microseconds, i.e.

supports blocking call with time-out.

  • server_socket [in] - server descriptor in listen state
  • ms_to_wait [in] - time to wait in microseconds
  • new_socket [out] - pointer to the new socket
  • peer_address [out] - pointer to address of the peer
Returns:
zero on success or time-out (check new_socket state - in the case of time-out, it will be set to 0). Be aware! [server_socket] must be a server (listening) socket, if you don't know about it, check it with getsockopt.

int nonblocking_recv hsocket  sk,
unsigned int  ms_to_wait,
char *  buf,
unsigned int  buflen,
unsigned int *  received
 

Receives incoming data like classic "recv" but returns through "ms_to_wait" microseconds, i.e.

supports blocking call with time-out.

  • sk [in] - socket descriptor
  • ms_to_wait [in] - time to wait in microseconds
  • buf [in/out] - buffer for received data
  • buflen [in] - length of the buffer
  • received [out] - length of received data in the buffer
Returns:
zero on success or time-out (check new value of [received] in the case of time-out, it will be set to 0).

int nonblocking_send hsocket  sk,
unsigned int  ms_to_wait,
const char *  buf,
unsigned int  buflen,
unsigned int *  sent
 

Sends data like classic "send" but returns through "ms_to_wait" microseconds, i.e.

supports blocking call with time-out.

  • sk [in] - socket descriptor
  • ms_to_wait [in] - time to wait in microseconds
  • buf [in/out] - buffer with data for send
  • buflen [in] - length of the data
  • sent [out] - length of sent data in the buffer
Returns:
zero on success or time-out (check new value of [sent] in the case of time-out, it will be set to 0).

int receive_socket hsocket  sock,
char *  recvbuff,
unsigned int  bufflen
 

Simple wrapper for recv function.

Not used.

int send_socket hsocket  sock,
const char *  buff,
unsigned int  len
 

Simple wrapper for send function.

Not used.


Variable Documentation

sockets_env sockets_os_enviroment
 


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