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 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, 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 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 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_t * | EGnewSocket (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 |
|
|
Definition at line 47 of file eg_net.ex.c. |
|
|
Definition at line 48 of file eg_net.ex.c. |
|
|
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.
|
|
|
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.
|
|
|
minimum length of the data queue in any socket connection. By default it is set to 64Kb
|
|
|
Minimum length of the incomming connection queue at the listening socket.
|
|
|
|
|
|
|
|
|
|
|
|
If set to one, use synchronization among sender and receiver.
|
|
|
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.
|
|
|
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;})
|
|
|
Initialize a socket structure.
|
|
|
send an int through a connected socket
|
|
|
|
|
|
send a short through a connected socket
|
|
|
|
|
|
Assure that the data queue don't overflow by using syncronizations calls between both ends of the connections.
|
|
|
Definition at line 49 of file eg_net.ex.c. |
|
||||||||||||
|
liberate (and close if open) a socket structure
|
|
||||||||||||||||
|
try to stablish a remote connection
|
|
|
close an established connection
|
|
||||||||||||
|
set a socket to wait for connections. Used as the server side of the connection
|
|
||||||||||||
|
recieve a char through a connected socket
|
|
||||||||||||
|
recieve a double through a connected socket. The current implementation has some limits, it tries to represent the number
|
|
||||||||||||
|
recieve an int through a connected socket
Definition at line 557 of file eg_net.c. Here is the call graph for this function: ![]() |
|
||||||||||||
|
recieve a short through a connected socket
Definition at line 493 of file eg_net.c. Here is the call graph for this function: ![]() |
|
||||||||||||||||
|
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: ![]() |
|
||||||||||||
|
recieve an unsigned int through a connected socket
|
|
||||||||||||
|
recieve a unsigned short through a connected socket
|
|
||||||||||||
|
send a char through a connected socket
|
|
||||||||||||
|
send a double through a connected socket. The current implementation has some limits, it tries to represent the number
|
|
||||||||||||
|
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: ![]() |
|
||||||||||||
|
send an unsigned int through a connected socket
|
|
||||||||||||
|
send a unsigned short through a connected socket
|
|
|
accept an incomming connection from another program/host, if no connection is on the queue, the program will block until one is found.
|
|
|
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.
|
|
|
close an established connection with another program/host
|
|
|
create a new socket structure initialized as empty
|
|
||||||||||||
|
Definition at line 118 of file eg_net.ex.c. Here is the call graph for this function: ![]() |
|
|
Definition at line 35 of file eg_net.ex.c. |
|
||||||||||||
|
Definition at line 54 of file eg_net.ex.c. Here is the call graph for this function: ![]() |
|
|
Definition at line 52 of file eg_net.ex.c. |
|
|
Definition at line 53 of file eg_net.ex.c. |
|
|
Definition at line 50 of file eg_net.ex.c. |
|
|
Definition at line 51 of file eg_net.ex.c. |
1.4.5