cp_socket is a 'server socket'. More...
#include <socket.h>
Data Fields | |
int | id |
socket id | |
int | port |
the port this socket listens on | |
int | backlog |
max backlog | |
struct timeval | delay |
max blocking time | |
int | connections_served |
number of connections accepted | |
struct timeval | created |
creation time | |
cp_hashlist * | fds |
all available file descriptors | |
cp_thread_pool * | tpool |
cp_thread pool (if requested) | |
int | poolsize_min |
min cp_thread count for cp_thread pool | |
int | poolsize_max |
max cp_thread count for cp_thread pool | |
unsigned int | fdn |
largest fd - needed for select() | |
cp_socket_strategy | strategy |
threadpool or callback | |
union { | |
cp_socket_thread_function thread_fn | |
cp_socket_callback callback | |
} | action |
placeholder for action | |
int | closing |
shutdown flag | |
void * | owner |
cp_vector * | shutdown_callback |
shutdown callback list |
cp_socket is a 'server socket'.
create a cp_socket to listen on a port, specify a callback to implemet your communication protocol (libcprops provides a basic http implementation you could plug in) and the strategy you want for handling handling multiple connections - use a thread pool to serve each connection on its own thread or a more select()-like approach.
If you create a socket with the CPSOCKET_STRATEGY_THREADPOOL, supply a thread function to handle communication once a connection has been accept()-ed. Your cp_thread function should close the connection when done and check the 'closing' flag, which is set to 1 on shutdown.
If you create a socket with the CPSOCKET_STRATEGY_CALLBACK, supply a callback to process incremental feeds as they come along.