Data Structures | |
| struct | EGsocket_t |
| structure for socket More... | |
Files | |
| file | eg_net.c |
| file | eg_net.ex.c |
| file | eg_net.h |
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) |
| #define | EGnetSendShort(skt, n) EGnetSendUshort(skt,(unsigned)n) |
| send a short through a connected socket | |
| #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 | |
| int | EGnetConnect (EGsocket_t *const skt, const char *host_name, unsigned port) |
| try to stablish a remote connection | |
| int | EGnetDisconnect (EGsocket_t *const skt) |
| close an established connection | |
| int | EGnetListen (EGsocket_t *const skt, unsigned 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 where , unfortunatelly, , 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, int *n) |
| recieve a short through a connected socket | |
| int | EGnetRecvString (EGsocket_t *const skt, char *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 *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 where , unfortunatelly, , 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 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 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 | |
| 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 unsigned int | nchars = 0 |
| static unsigned | port = 0 |
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).
| #define BOSS 1 |
| #define CLIENT 2 |
Definition at line 40 of file eg_net.ex.c.
Referenced by main(), and parseargs().
| #define EG_NET_ALLOW_NON_BLOCKING 0 |
| #define EG_NET_CONFIRM 0 |
| #define EG_NET_DATA_QUEUE_SIZE 131072U |
| #define EG_NET_LISTEN_QUEUE_SIZE 16384U |
| #define EG_NET_SYNCHRONIZE 0 |
| #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 | ) |
({\
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
| #define EGnetInitSocket | ( | skt | ) | memset(skt,0,sizeof(EGsocket_t)) |
Initialize a socket structure.
Definition at line 128 of file eg_net.h.
Referenced by main().
| #define EGnetSendInt | ( | skt, | ||
| n | ||||
| ) | EGnetSendUint(skt,(unsigned) n) |
| #define EGnetSendInt | ( | skt, | ||
| n | ||||
| ) | EGnetSendUint(skt,(unsigned) n) |
| #define EGnetSendShort | ( | skt, | ||
| n | ||||
| ) | EGnetSendUshort(skt,(unsigned)n) |
| #define EGnetSendShort | ( | skt, | ||
| n | ||||
| ) | EGnetSendUshort(skt,(unsigned)n) |
| #define EGnetSynchronize | ( | skt, | ||
| type, | ||||
| length | ||||
| ) |
| #define KILL 3 |
| int EGnetConnect | ( | EGsocket_t *const | skt, | |
| const char * | host_name, | |||
| unsigned | port | |||
| ) |
| int EGnetDisconnect | ( | EGsocket_t *const | skt | ) |
| int EGnetListen | ( | EGsocket_t *const | skt, | |
| unsigned | p | |||
| ) |
set a socket to wait for connections. Used as the server side of the connection
Referenced by main().
| int EGnetRecvChar | ( | EGsocket_t *const | skt, | |
| char *const | 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
where
, unfortunatelly,
, and numbers that can't be represented in this form won't be transmitted in a right way.
Referenced by main().
| int EGnetRecvInt | ( | EGsocket_t *const | skt, | |
| int * | n | |||
| ) |
| int EGnetRecvShort | ( | EGsocket_t *const | skt, | |
| int * | n | |||
| ) |
| 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)
| int EGnetRecvUint | ( | EGsocket_t *const | skt, | |
| unsigned int * | n | |||
| ) |
| int EGnetRecvUshort | ( | EGsocket_t *const | skt, | |
| unsigned * | n | |||
| ) |
| int EGnetSendChar | ( | EGsocket_t *const | skt, | |
| const int | 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
where
, unfortunatelly,
, and numbers that can't be represented in this form won't be transmitted in a right way.
Referenced by main().
| 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).
| int EGnetSendUint | ( | EGsocket_t *const | skt, | |
| unsigned int | n | |||
| ) |
| int EGnetSendUshort | ( | EGsocket_t *const | skt, | |
| unsigned | n | |||
| ) |
| 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.
Referenced by main().
| 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
Referenced by main().
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 110 of file eg_net.ex.c.
References BOSS, CHECKRVAL, CLIENT, EGlib_info(), EGlib_version(), EGnetConnect(), EGnetDisconnect(), EGnetInitSocket, EGnetListen(), EGnetRecvChar(), EGnetRecvDouble(), EGnetRecvInt(), EGnetRecvShort(), EGnetRecvUint(), EGnetRecvUshort(), EGnetSendChar(), EGnetSendDouble(), EGnetSendInt, EGnetSendShort, EGnetSendUint(), EGnetSendUshort(), EGnetStartRead(), EGnetStopRead(), EGrand(), EGrandInit(), EGsetLimits(), EGsigSet, hname, KILL, MESSAGE, mode, nchars, parseargs(), port, and TEST.

| static void net_usage | ( | char * | program | ) | [static] |
| static int parseargs | ( | int | argc, | |
| char ** | argv | |||
| ) | [static] |
Definition at line 46 of file eg_net.ex.c.
References CLIENT, hname, MESSAGE, mode, nchars, net_usage(), and port.
Referenced by main().

char* hname = 0 [static] |
Definition at line 44 of file eg_net.ex.c.
Referenced by main(), and parseargs().
int mode = 0 [static] |
Definition at line 45 of file eg_net.ex.c.
Referenced by main(), and parseargs().
unsigned int nchars = 0 [static] |
Definition at line 42 of file eg_net.ex.c.
Referenced by main(), and parseargs().
unsigned port = 0 [static] |
Definition at line 43 of file eg_net.ex.c.
Referenced by main(), and parseargs().
1.7.1