net_layer.h File Reference
#include "magma_setup.h"Defines | |
| #define | SEND_FLAGS 0 |
| #define | RECV_FLAGS 0 |
| #define | BIND_RETRY 60 |
| #define | MAX_TRANSMIT_RETRY 16 |
| #define | MAGMA_PORT 12000 |
| #define | MAX_SERVER_CONNECTIONS 8 |
| #define | send_uint8_t(s, i) send(s,&i,sizeof(uint8_t),SEND_FLAGS) |
| #define | recv_uint8_t(s, i) recv(s,&i,sizeof(uint8_t),SEND_FLAGS) |
| #define | send_uint16_t(s, i) |
| #define | recv_uint16_t(s, i) |
| #define | send_uint32_t(s, i) |
| #define | recv_uint32_t(s, i) |
| #define | send_uint64_t(s, i) |
| #define | recv_uint64_t(s, i) |
| #define | netstrcpy netstrcpy_peek |
Functions | |
| int | get_client_socket (char *ipaddr, int port) |
| int | xsend (int s, const void *buf, size_t size) |
| int | xread (int s, void *buf, size_t size) |
| int | netstrcpy_single_char (int s, char *string, int max) |
| int | netstrcpy_peek (int s, char *string, int max) |
| int | xnetstrcpy (int s, char **string, int max) |
| int | cnetstrsend (int s, const char *string) |
| int | cnetstrcpy (int s, char **string) |
| void | transmit_heartbeat (int s, struct sockaddr_in *peer, socklen_t *peer_len) |
Define Documentation
| #define BIND_RETRY 60 |
usually timeout for unavailable sockets is set to 60 seconds
| #define MAGMA_PORT 12000 |
default magma port
| #define MAX_SERVER_CONNECTIONS 8 |
backlog value used by listen
| #define MAX_TRANSMIT_RETRY 16 |
how many times should a recv/send call should try to transfer data? used by xsend and xread
| #define netstrcpy netstrcpy_peek |
| #define RECV_FLAGS 0 |
| #define recv_uint16_t | ( | s, | |||
| i | ) |
Value:
{\
uint16_t inet;\
recv(s,&inet,sizeof(uint16_t),RECV_FLAGS);\
i = ntohs(inet);\
}
| #define recv_uint32_t | ( | s, | |||
| i | ) |
Value:
{\
recv(s,&(i),sizeof(uint32_t),RECV_FLAGS);\
i = ntohl(i);\
}
| #define recv_uint64_t | ( | s, | |||
| i | ) |
Value:
{\
recv(s,&(i),sizeof(uint64_t),RECV_FLAGS);\
i = magma_ntohll(i);\
}
| #define recv_uint8_t | ( | s, | |||
| i | ) | recv(s,&i,sizeof(uint8_t),SEND_FLAGS) |
macro to receive 8 bit unsigned integers
| #define SEND_FLAGS 0 |
| #define send_uint16_t | ( | s, | |||
| i | ) |
Value:
{\
uint16_t inet = htons(i);\
send(s,&inet,sizeof(uint16_t),SEND_FLAGS);\
}
| #define send_uint32_t | ( | s, | |||
| i | ) |
Value:
{\
uint32_t inet = htonl(i);\
send(s,&inet,sizeof(uint32_t),SEND_FLAGS);\
}
| #define send_uint64_t | ( | s, | |||
| i | ) |
Value:
{\
uint64_t inet = magma_htonll(i);\
send(s,&inet,sizeof(uint64_t),SEND_FLAGS);\
}
| #define send_uint8_t | ( | s, | |||
| i | ) | send(s,&i,sizeof(uint8_t),SEND_FLAGS) |
macro to send 8 bit unsigned integers
Function Documentation
| int cnetstrcpy | ( | int | s, | |
| char ** | string | |||
| ) |
Counterpart of cnetstrsend. *string is dynamically allocated and should be freed by outside code.
- Parameters:
-
s network socket string memory buffer which contains the string to be sent
- Returns:
- read bytes
| int cnetstrsend | ( | int | s, | |
| const char * | string | |||
| ) |
Send a string over the wire using a counter on top of it to transmit string length
- Parameters:
-
s network socket string memory buffer which contains the string to be sent
- Returns:
- sent bytes
| int get_client_socket | ( | char * | ipaddr, | |
| int | port | |||
| ) |
provides a network socket initialized for flare protocol
- Parameters:
-
ipaddr string rappresenting remote IP address port remote port
- Returns:
- new socket, 0 on failure
| int netstrcpy_peek | ( | int | s, | |
| char * | string, | |||
| int | max | |||
| ) |
copy a string of max chars directly from the network socket s. this variant uses TCP peek option to inspect available data without removing it from the buffer
- Parameters:
-
s network socket string memory buffer to save the string to be received max dimension of memory buffer string
- Returns:
- read bytes
| int netstrcpy_single_char | ( | int | s, | |
| char * | string, | |||
| int | max | |||
| ) |
copy a string of max chars directly from the network socket s. this variant read 1 char at time until \0 is reached
- Parameters:
-
s network socket string memory buffer to save the string to be received max dimension of memory buffer string
- Returns:
- read bytes
| void transmit_heartbeat | ( | int | s, | |
| struct sockaddr_in * | peer, | |||
| socklen_t * | peer_len | |||
| ) |
transmit 1 if server is still alive.
- Parameters:
-
s network socket peer remote address peer_len size of peer structure
| int xnetstrcpy | ( | int | s, | |
| char ** | string, | |||
| int | max | |||
| ) |
copy a string of max chars directly from the network socket s. *string buffer is dynamically allocated and should be freed by outside code.
- Parameters:
-
s network socket string memory buffer to save the string to be received max dimension of memory buffer string
- Returns:
- read bytes
| int xread | ( | int | s, | |
| void * | buf, | |||
| size_t | size | |||
| ) |
try to read as many bytes as needed
- Parameters:
-
s network socket buf memory area to save incoming data size dimension of memory area pointed by buf
- Returns:
- read bytes
| int xsend | ( | int | s, | |
| const void * | buf, | |||
| size_t | size | |||
| ) |
Guarantee that all provided buffer will be delivered over the wire
- Parameters:
-
s network socket buf the buffer to be written size buffer size to be written
- Returns:
- sent bytes