c-template
|
TCP socket servers, clients, and tooling for working with sockets. More...
#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/time.h>
#include "socket.h"
#include "../../utils/logger.h"
#include "../../sync/wait_group.h"
Go to the source code of this file.
Data Structures | |
struct | socket_server |
a generic tcp socket server using file descriptor socket_number it uses a dedicated pthread for accepting new client connections, with each connection being processed in another pthread in detached state. socket uses SO_REUSEADDR More... | |
struct | client_conn |
a structure containing a file descriptor and address information More... | |
struct | conn_handle_data |
struct containing arguments passed into pthread More... | |
Typedefs | |
typedef struct socket_server | socket_server |
typedef struct client_conn | client_conn |
typedef struct conn_handle_data | conn_handle_data |
Functions | |
socket_server * | new_socket_server (addr_info hints, thread_logger *thl, int max_conns, char *port) |
returns a new socket server bound to the port number and ready to accept connections More... | |
void * | async_listen_func (void *data) |
listens for new connections and spawns a thread to process the connection thread that is created to process the connection runs as a detached thread will poll for new connections to accept every 500 miliseconds More... | |
void * | async_handle_conn_func (void *data) |
handles connections in a dedicated pthread is laucnched in a pthread by async_listen_func when any new connection is received More... | |
client_conn * | accept_client_conn (socket_server *srv) |
helper function for accepting client connections times out new attempts if they take 3 seconds or more More... | |
TCP socket servers, clients, and tooling for working with sockets.
uses wait_group.h to provide lightweight synchronization between pthreads
async_handle_conn_func
to suit your needs as right now it is just an echo client it is likely you will need to have #define _POSIX_C_SOURCE 201112L
see the following for more information
Definition in file socket_server.h.
client_conn* accept_client_conn | ( | socket_server * | srv | ) |
helper function for accepting client connections times out new attempts if they take 3 seconds or more
void* async_handle_conn_func | ( | void * | data | ) |
handles connections in a dedicated pthread
is laucnched in a pthread by async_listen_func when any new connection is received
data | void * to a conn_handle_data object |
select
to determine if we can read data from the connection void* async_listen_func | ( | void * | data | ) |
listens for new connections and spawns a thread to process the connection thread that is created to process the connection runs as a detached thread will poll for new connections to accept every 500 miliseconds
data | void pointer to a socket_server struct |
socket_server* new_socket_server | ( | addr_info | hints, |
thread_logger * | thl, | ||
int | max_conns, | ||
char * | port | ||
) |
returns a new socket server bound to the port number and ready to accept connections