Macros | |
#define | MIN(x, y) x < y ? x : y |
Functions | |
int | initiate_socket () |
Initiates a socket. | |
void | close_socket (int sock) |
Closes a socket. | |
struct socket_request_listener | create_socket_request_listener (int sock) |
Creates a socket request listener. | |
int | socket_request_listen (struct socket_request_listener *listener, int server_sock, int timeout) |
Listens for socket requests. | |
int | socket_request_receive (struct socket_request_listener *listener, int client_sock, char *buffer, int size, int timeout, int flags) |
Receives a socket request. | |
struct peer * | create_peer (int socket) |
Creates a peer structure. | |
void | free_peer (struct peer *peer) |
int | receive_message (void *p, char **buffer, int size, int timeout, int flags) |
Receives a message from a peer. | |
int | read_messages (int bytes_received, char *msg_buffer, void *p) |
Reads messages from a buffer. | |
int | send_message (int socket, const char *message, int flags) |
Sends a message through a socket. | |
void | remove_message_handler_by_index (void *p, int i) |
Removes a message handler by its index. | |
void | remove_message_handling (void *p, char *msg) |
Removes a message handler by its message. | |
void | add_message_handler (void *p, char *msg, int(*callback)(int, char *, void *, void **), int lifespan, int argc, void **data) |
Adds a message handler. | |
#define MIN | ( | x, | |
y | |||
) | x < y ? x : y |
int initiate_socket | ( | ) |
Initiates a socket.
void close_socket | ( | int | sock | ) |
Closes a socket.
sock | The file descriptor of the socket to close. |
struct socket_request_listener create_socket_request_listener | ( | int | sock | ) |
Creates a socket request listener.
sock | The file descriptor of the socket to listen on. |
int socket_request_listen | ( | struct socket_request_listener * | listener, |
int | server_sock, | ||
int | timeout | ||
) |
Listens for socket requests.
listener | Pointer to the socket request listener. |
server_sock | The file descriptor of the server socket. |
timeout | The timeout value for listening, in milliseconds. |
int socket_request_receive | ( | struct socket_request_listener * | listener, |
int | client_sock, | ||
char * | buffer, | ||
int | size, | ||
int | timeout, | ||
int | flags | ||
) |
Receives a socket request.
listener | Pointer to the socket request listener. |
client_sock | The file descriptor of the client socket. |
buffer | Pointer to the buffer to store the received data. |
size | The size of the buffer. |
timeout | The timeout value for receiving, in milliseconds. |
flags | Flags for receiving data. |
struct peer * create_peer | ( | int | socket | ) |
Creates a peer structure.
socket | The file descriptor of the socket associated with the peer. |
void free_peer | ( | struct peer * | peer | ) |
int receive_message | ( | void * | peer, |
char ** | buffer, | ||
int | size, | ||
int | timeout, | ||
int | flags | ||
) |
Receives a message from a peer.
peer | Pointer to the peer structure. |
buffer | Pointer to the buffer to store the received message. |
size | The size of the buffer. |
timeout | The timeout value for receiving, in milliseconds. |
flags | Flags for receiving data. |
int read_messages | ( | int | bytes_received, |
char * | msg_buffer, | ||
void * | p | ||
) |
Reads messages from a buffer.
bytes_received | The number of bytes received. |
msg_buffer | Pointer to the buffer containing the messages. |
p | Pointer to additional data. |
int send_message | ( | int | socket, |
const char * | message, | ||
int | flags | ||
) |
Sends a message through a socket.
socket | The file descriptor of the socket. |
message | Pointer to the message to send. |
flags | Flags for sending data. |
void remove_message_handler_by_index | ( | void * | p, |
int | index | ||
) |
Removes a message handler by its index.
p | Pointer to the data structure containing the message handlers. |
index | The index of the message handler to remove. |
void remove_message_handling | ( | void * | p, |
char * | msg | ||
) |
Removes a message handler by its message.
p | Pointer to the data structure containing the message handlers. |
msg | Pointer to the message associated with the handler to remove. |
void add_message_handler | ( | void * | peer, |
char * | msg, | ||
int(*)(int, char *, void *, void **) | callback, | ||
int | lifespan, | ||
int | argc, | ||
void ** | data | ||
) |
Adds a message handler.
peer | Pointer to the peer structure. |
msg | Pointer to the message associated with the handler. |
callback | Pointer to the callback function to handle the message. |
lifespan | The lifespan of the message handler. |
argc | The number of arguments for the callback function. |
data | Pointer to the array of arguments for the callback function. |