EGnet


Detailed Description

This header contain the definitions to make basic client/server communications. The protocol used to comunicate is TCP/IP. and the type of communication is permanent (within each cycle connect/disconnect start_read/stop_read).

Version:
0.9.1
History:


Files

file  eg_net.c
file  eg_net.ex.c
file  eg_net.h

Data Structures

struct  EGsocket_t
 structure for socket More...

Defines

#define BOSS   1
#define CLIENT   2
#define EG_NET_ALLOW_NON_BLOCKING   0
 Set to one to enable non-blocking calls, zero to disable them. What happen in that case is that non-blocking calls behave as regular blocking calls.
#define EG_NET_CONFIRM   0
 If set to one, check that the information send was properly received, this may slow down the code by a significant factor, and also may fix synchronization issues without enabling EG_NET_SYNCHRONIZE.
#define EG_NET_DATA_QUEUE_SIZE   131072U
 minimum length of the data queue in any socket connection. By default it is set to 64Kb
#define EG_NET_LISTEN_QUEUE_SIZE   16384U
 Minimum length of the incomming connection queue at the listening socket.
#define EG_NET_MARKER   '5'
#define EG_NET_RECEIVE   1
#define EG_NET_SEND   0
#define EG_NET_SYNCHRONIZE   0
 If set to one, use synchronization among sender and receiver.
#define EG_NET_TCPIP_OVERHEAD   128
 Overhead of a MAC/TCP/IP package over the data part of the packet, note that the MAC header is about 14 bytes long, that IP has an overhead of 20 bytes plus 4 bytes for options and padding. TCP other 20 bytes plus up to 44 bytes for options and padding, thus the overhead is between 58 and 102 bytes. Then to send x bytes across a TCP/IP connection, we actually send x bytes + [58-102] bytes. This overhead is the constant that we define bellow. For details on the structure of the MAC/IP/TCP headers, see the TCP/IP description. Note also that we shouldn't send packets of length above 572 bytes, thus the actual data length should be less than 470 bytes.
#define EGnetClearSocket(__lskt)
 clear a socket structure and leave it ready to be freed
#define EGnetInitSocket(skt)   memset(skt,0,sizeof(EGsocket_t))
 Initialize a socket structure.
#define EGnetSendInt(skt, n)   EGnetSendUint(skt,(unsigned) n)
 send an int through a connected socket
#define EGnetSendInt(skt, n)   EGnetSendUint(skt,(unsigned) n)
#define EGnetSendShort(skt, n)   EGnetSendUshort(skt,(unsigned)n)
 send a short through a connected socket
#define EGnetSendShort(skt, n)   EGnetSendUshort(skt,(unsigned)n)
#define EGnetSynchronize(skt, type, length)
 Assure that the data queue don't overflow by using syncronizations calls between both ends of the connections.
#define KILL   3

Functions

void EGfreeSocket (void *skt, EGmemPool_t *mem)
 liberate (and close if open) a socket structure
int EGnetConnect (EGsocket_t *const skt, const char *host_name, unsigned short port)
 try to stablish a remote connection
int EGnetDisconnect (EGsocket_t *const skt)
 close an established connection
int EGnetListen (EGsocket_t *const skt, unsigned short p)
 set a socket to wait for connections. Used as the server side of the connection
int EGnetRecvChar (EGsocket_t *const skt, char *const c)
 recieve a char through a connected socket
int EGnetRecvDouble (EGsocket_t *const skt, double *const d)
 recieve a double through a connected socket. The current implementation has some limits, it tries to represent the number $ d = 2^ex $ where $0.5\leq|x|<1$ , unfortunatelly, $ |e|\leq 128 $ , and numbers that can't be represented in this form won't be transmitted in a right way.
int EGnetRecvInt (EGsocket_t *const skt, int *n)
 recieve an int through a connected socket
int EGnetRecvShort (EGsocket_t *const skt, short *n)
 recieve a short through a connected socket
int EGnetRecvString (EGsocket_t *const skt, char *const const str, size_t max_size)
 recieve a string through a connected socket, the string must have allocated memory and its maximum size be max_size (including the '\0' char)
int EGnetRecvUint (EGsocket_t *const skt, unsigned int *n)
 recieve an unsigned int through a connected socket
int EGnetRecvUshort (EGsocket_t *const skt, unsigned short *n)
 recieve a unsigned short through a connected socket
int EGnetSendChar (EGsocket_t *const skt, const int c)
 send a char through a connected socket
int EGnetSendDouble (EGsocket_t *const skt, const double d)
 send a double through a connected socket. The current implementation has some limits, it tries to represent the number $ d = 2^ex $ where $0.5\leq|x|<1$ , unfortunatelly, $ |e|\leq 128 $ , and numbers that can't be represented in this form won't be transmitted in a right way.
int EGnetSendString (EGsocket_t *const skt, const char *const const str)
 send a string through a connected socket, it will send up to the '\0' char at the end of the string (including it).
int EGnetSendUint (EGsocket_t *const skt, unsigned int n)
 send an unsigned int through a connected socket
int EGnetSendUshort (EGsocket_t *const skt, unsigned short n)
 send a unsigned short through a connected socket
int EGnetStartRead (EGsocket_t *const skt)
 accept an incomming connection from another program/host, if no connection is on the queue, the program will block until one is found.
int EGnetStartReadNB (EGsocket_t *const skt)
 accept an incomming connection from another program/host. If no connection is on the queue (of incomming connections), the program will return EAGAIN, otherwise it return zero on success and non zero (1) in error.
int EGnetStopRead (EGsocket_t *const skt)
 close an established connection with another program/host
EGsocket_tEGnewSocket (EGmemPool_t *mem)
 create a new socket structure initialized as empty
int main (int argc, char **argv)
static void net_usage (char *program)
static int parseargs (int argc, char **argv)

Variables

static char * hname = 0
static int mode = 0
static int nchars = 0
static unsigned short port = 0


Define Documentation

#define BOSS   1
 

Examples:
eg_net.ex.c.

Definition at line 47 of file eg_net.ex.c.

#define CLIENT   2
 

Examples:
eg_net.ex.c.

Definition at line 48 of file eg_net.ex.c.

#define EG_NET_ALLOW_NON_BLOCKING   0
 

Set to one to enable non-blocking calls, zero to disable them. What happen in that case is that non-blocking calls behave as regular blocking calls.

Definition at line 132 of file eg_net.h.

#define EG_NET_CONFIRM   0
 

If set to one, check that the information send was properly received, this may slow down the code by a significant factor, and also may fix synchronization issues without enabling EG_NET_SYNCHRONIZE.

Definition at line 79 of file eg_net.h.

#define EG_NET_DATA_QUEUE_SIZE   131072U
 

minimum length of the data queue in any socket connection. By default it is set to 64Kb

Definition at line 103 of file eg_net.h.

#define EG_NET_LISTEN_QUEUE_SIZE   16384U
 

Minimum length of the incomming connection queue at the listening socket.

Definition at line 108 of file eg_net.h.

#define EG_NET_MARKER   '5'
 

Definition at line 357 of file eg_net.c.

#define EG_NET_RECEIVE   1
 

Definition at line 356 of file eg_net.c.

#define EG_NET_SEND   0
 

Definition at line 355 of file eg_net.c.

#define EG_NET_SYNCHRONIZE   0
 

If set to one, use synchronization among sender and receiver.

Definition at line 83 of file eg_net.h.

#define EG_NET_TCPIP_OVERHEAD   128
 

Overhead of a MAC/TCP/IP package over the data part of the packet, note that the MAC header is about 14 bytes long, that IP has an overhead of 20 bytes plus 4 bytes for options and padding. TCP other 20 bytes plus up to 44 bytes for options and padding, thus the overhead is between 58 and 102 bytes. Then to send x bytes across a TCP/IP connection, we actually send x bytes + [58-102] bytes. This overhead is the constant that we define bellow. For details on the structure of the MAC/IP/TCP headers, see the TCP/IP description. Note also that we shouldn't send packets of length above 572 bytes, thus the actual data length should be less than 470 bytes.

Definition at line 97 of file eg_net.h.

#define EGnetClearSocket __lskt   ) 
 

Value:

({\
  EGsocket_t*const _EGskt = (EGsocket_t*)(__lskt);\
  if(_EGskt->s_fd) close(_EGskt->s_fd);\
  if(_EGskt->f_fd) close(_EGskt->f_fd);\
  memset(_EGskt,0,sizeof(EGsocket_t));\
  0;})
clear a socket structure and leave it ready to be freed

Definition at line 140 of file eg_net.h.

#define EGnetInitSocket skt   )     memset(skt,0,sizeof(EGsocket_t))
 

Initialize a socket structure.

Definition at line 136 of file eg_net.h.

#define EGnetSendInt skt,
 )     EGnetSendUint(skt,(unsigned) n)
 

send an int through a connected socket

Definition at line 229 of file eg_net.h.

#define EGnetSendInt skt,
 )     EGnetSendUint(skt,(unsigned) n)
 

Examples:
eg_net.ex.c.

Definition at line 554 of file eg_net.c.

#define EGnetSendShort skt,
 )     EGnetSendUshort(skt,(unsigned)n)
 

send a short through a connected socket

Definition at line 210 of file eg_net.h.

#define EGnetSendShort skt,
 )     EGnetSendUshort(skt,(unsigned)n)
 

Examples:
eg_net.ex.c.

Definition at line 490 of file eg_net.c.

#define EGnetSynchronize skt,
type,
length   ) 
 

Assure that the data queue don't overflow by using syncronizations calls between both ends of the connections.

Parameters:
skt socket where we are working.
type either EG_NET_SEND or EG_NET RECEIVE.
length bytes being transfered.

Definition at line 405 of file eg_net.c.

#define KILL   3
 

Examples:
eg_net.ex.c.

Definition at line 49 of file eg_net.ex.c.


Function Documentation

void EGfreeSocket void *  skt,
EGmemPool_t mem
 

liberate (and close if open) a socket structure

Examples:
eg_net.ex.c.

Definition at line 38 of file eg_net.c.

int EGnetConnect EGsocket_t *const   skt,
const char *  host_name,
unsigned short  port
 

try to stablish a remote connection

Examples:
eg_net.ex.c.

Definition at line 115 of file eg_net.c.

int EGnetDisconnect EGsocket_t *const   skt  ) 
 

close an established connection

Examples:
eg_net.ex.c.

Definition at line 187 of file eg_net.c.

int EGnetListen EGsocket_t *const   skt,
unsigned short  p
 

set a socket to wait for connections. Used as the server side of the connection

Examples:
eg_net.ex.c.

Definition at line 47 of file eg_net.c.

int EGnetRecvChar EGsocket_t *const   skt,
char *const   c
 

recieve a char through a connected socket

Examples:
eg_net.ex.c.

Definition at line 428 of file eg_net.c.

int EGnetRecvDouble EGsocket_t *const   skt,
double *const   d
 

recieve a double through a connected socket. The current implementation has some limits, it tries to represent the number $ d = 2^ex $ where $0.5\leq|x|<1$ , unfortunatelly, $ |e|\leq 128 $ , and numbers that can't be represented in this form won't be transmitted in a right way.

Examples:
eg_net.ex.c.

Definition at line 649 of file eg_net.c.

int EGnetRecvInt EGsocket_t *const   skt,
int *  n
 

recieve an int through a connected socket

Examples:
eg_net.ex.c.

Definition at line 557 of file eg_net.c.

Here is the call graph for this function:

int EGnetRecvShort EGsocket_t *const   skt,
short *  n
 

recieve a short through a connected socket

Examples:
eg_net.ex.c.

Definition at line 493 of file eg_net.c.

Here is the call graph for this function:

int EGnetRecvString EGsocket_t *const   skt,
char *const const   exstr,
size_t  max_size
 

recieve a string through a connected socket, the string must have allocated memory and its maximum size be max_size (including the '\0' char)

Definition at line 722 of file eg_net.c.

Here is the call graph for this function:

int EGnetRecvUint EGsocket_t *const   skt,
unsigned int *  n
 

recieve an unsigned int through a connected socket

Examples:
eg_net.ex.c.

Definition at line 532 of file eg_net.c.

int EGnetRecvUshort EGsocket_t *const   skt,
unsigned short *  n
 

recieve a unsigned short through a connected socket

Examples:
eg_net.ex.c.

Definition at line 470 of file eg_net.c.

int EGnetSendChar EGsocket_t *const   skt,
const int  c
 

send a char through a connected socket

Examples:
eg_net.ex.c.

Definition at line 409 of file eg_net.c.

int EGnetSendDouble EGsocket_t *const   skt,
const double  exd
 

send a double through a connected socket. The current implementation has some limits, it tries to represent the number $ d = 2^ex $ where $0.5\leq|x|<1$ , unfortunatelly, $ |e|\leq 128 $ , and numbers that can't be represented in this form won't be transmitted in a right way.

Examples:
eg_net.ex.c.

Definition at line 569 of file eg_net.c.

int EGnetSendString EGsocket_t *const   skt,
const char *const const   exstr
 

send a string through a connected socket, it will send up to the '\0' char at the end of the string (including it).

Definition at line 705 of file eg_net.c.

Here is the call graph for this function:

int EGnetSendUint EGsocket_t *const   skt,
unsigned int  n
 

send an unsigned int through a connected socket

Examples:
eg_net.ex.c.

Definition at line 505 of file eg_net.c.

int EGnetSendUshort EGsocket_t *const   skt,
unsigned short  n
 

send a unsigned short through a connected socket

Examples:
eg_net.ex.c.

Definition at line 445 of file eg_net.c.

int EGnetStartRead EGsocket_t *const   skt  ) 
 

accept an incomming connection from another program/host, if no connection is on the queue, the program will block until one is found.

Examples:
eg_net.ex.c.

Definition at line 276 of file eg_net.c.

int EGnetStartReadNB EGsocket_t *const   skt  ) 
 

accept an incomming connection from another program/host. If no connection is on the queue (of incomming connections), the program will return EAGAIN, otherwise it return zero on success and non zero (1) in error.

Definition at line 202 of file eg_net.c.

int EGnetStopRead EGsocket_t *const   skt  ) 
 

close an established connection with another program/host

Examples:
eg_net.ex.c.

Definition at line 339 of file eg_net.c.

EGsocket_t * EGnewSocket EGmemPool_t mem  ) 
 

create a new socket structure initialized as empty

Examples:
eg_net.ex.c.

Definition at line 30 of file eg_net.c.

int main int  argc,
char **  argv
 

Definition at line 118 of file eg_net.ex.c.

Here is the call graph for this function:

static void net_usage char *  program  )  [static]
 

Examples:
eg_net.ex.c.

Definition at line 35 of file eg_net.ex.c.

static int parseargs int  argc,
char **  argv
[static]
 

Definition at line 54 of file eg_net.ex.c.

Here is the call graph for this function:


Variable Documentation

char* hname = 0 [static]
 

Examples:
eg_net.ex.c.

Definition at line 52 of file eg_net.ex.c.

int mode = 0 [static]
 

Examples:
eg_net.ex.c.

Definition at line 53 of file eg_net.ex.c.

int nchars = 0 [static]
 

Examples:
eg_net.ex.c.

Definition at line 50 of file eg_net.ex.c.

unsigned short port = 0 [static]
 

Examples:
eg_net.ex.c.

Definition at line 51 of file eg_net.ex.c.


Generated on Mon Jan 30 08:55:41 2006 for EGlib by  doxygen 1.4.5