I've figured out how cbitcoin will handle sockets. cbitcoin will have dependencies for events-based, non-blocking sockets. It should work with libevent though I need to learn more about how to use lubevent to make sure my library is compatible. My threading dependencies should work with POSIX threads nicely.
Here are the threading and socket dependencies as I have them so far (These are weakly linked function prototypes):
// THREADING DEPENDENCIES
/*
@brief Starts a new thread. The thread should be joinable.
@param threadID The ID for the thread to be set with newly allocated memory, used to refer to the threads in other functions.
@param startFunction The function to be called as the starting point of the new thread.
@param args A pointer to the arguments for the starting function.
@returns true if the thread was successfully created and false if the thread could not be created.
*/
bool CBStartThread(void * threadID,void * (*startFunction)(void *),void * args);
/*
@brief Ends the calling thread.
*/
void CBEndThread(void);
/*
@brief Waits for a thread to terminate.
@param threadID The ID for the thread.
*/
void CBThreadJoin(void * threadID);
/*
@brief Frees any resources related to a thread, including the ID.
@param threadID The ID for the thread.
*/
void CBFreeThread(void * threadID);
/*
@brief Creates a new mutex.
@param mutexID The mutex id to be set with newly allocated new memory.
@returns true if the mutex was successfully created and false if the mutex could not be created.
*/
bool CBNewMutex(void * mutexID);
/*
@brief Frees a new mutex including the ID. It is assured that no thread locks are active before this is called as threads should be canceled.
@param mutexID The mutex id to free.
*/
void CBFreeMutex(void * mutexID);
/*
@brief Obtains a mutex lock when next available.
@param mutexID The mutex id.
*/
void CBMutexLock(void * mutexID);
/*
@brief Unlocks a mutex for other threads.
@param mutexID The mutex id.
*/
void CBMutexUnlock(void * mutexID);
// NETWORKING DEPENDENCIES
/*
@brief Creates a new TCP/IPv6 socket and binds it to the given IPv6 address and port. The socket should use a non-blocking mode.
@param socketID The socket id to be set with newly allocated new memory.
@returns true if the socket was successfully created and false if the socket could not be created.
*/
bool CBNewSocket(void * socketID);
/*
@brief Binds the local address and a port number to a socket.
@param socketID The socket id
@param port The port to bind to.
@returns true if the bind was sucessful and false otherwise.
*/
bool CBSocketBind(void * socketID,u_int16_t port);
/*
@brief Begin connecting to an external host with a socket. This should be non-blocking.
@param socketID The socket id
@param IP 16 bytes for an IPv6 address to connect to.
@param port Port to connect to.
@param onConnect Pointer to the function that should be called when the connection has been sucessful.
@param onConnectArg Pointer to send to "onConnect".
@returns true if the function was sucessful and false otherwise.
*/
bool CBSocketConnect(void * socketID,u_int8_t * IP,u_int16_t port,void (*onConnect)(void *),void * onConnectArg);
/*
@brief Begin listening for incomming connections on a bound socket. This should be non-blocking.
@param socketID The socket id
@param maxConnections The maximum incomming connections to allow.
@param onAccept Pointer to the function that should be called when the socket is ready for accepting an incomming connection.
@param onAcceptArg Pointer to send to "onAccept".
@returns true if function was sucessful and false otherwise.
*/
bool CBSocketListen(void * socketID,u_int16_t maxConnections,void (*onAccept)(void *),void * onAcceptArg);
/*
@brief Accepts an incomming connections on a bound socket. This should be non-blocking.
@param socketID The socket id
@param connectionSocketID A socket id for a new socket for the connection.
@param IP 16 bytes to be set by the function for the IP of the incomming connection.
@returns true if function was sucessful and false otherwise.
*/
bool CBSocketAccept(void * socketID,void * connectionSocketID,u_int8_t * IP);
/*
@brief Sets a function pointer for the event where a socket is available for sending data.
@param socketID The socket id
@param onCanSend The function to call for the event.
@param onCanSendArg A pointer to pass to the "onCanWrite" function.
@returns true if function was sucessful and false otherwise.
*/
bool CBSocketCanSendEvent(void * socketID,void (*onCanSend)(void *),void * onCanSendArg);
/*
@brief Sets a function pointer for the event where a socket is available for receiving data.
@param socketID The socket id
@param onCanReceive The function to call for the event.
@param onCanWriteArg A pointer to pass to the "onCanWrite" function.
@returns true if function was sucessful and false otherwise.
*/
bool CBSocketCanReceiveEvent(void * socketID,void (*onCanReceive)(void *),void * onCanReceiveArg);
/*
@brief Sends data to a socket. This should be non-blocking.
@param socketID The socket id to send to.
@param data The data bytes to send.
@param len The length of the data to send.
@returns The number of bytes actually sent and any number less than 0 on failure that suggests further data cannot be sent.
*/
int32_t CBSocketSend(void * socketID,u_int8_t * data,u_int32_t len);
/*
@brief Receives data from a socket. This should be non-blocking.
@param socketID The socket id to receive data from.
@param data The data bytes to write the data to.
@param len The length of the data.
@returns The number of bytes actually written into "data", 0 on connection closure and any number less than 0 on failure.
*/
int32_t CBSocketReceive(void * socketID,u_int8_t * data,u_int32_t len);
/*
@brief Closes a socket. The id should be freed, as well as any other data relating to this socket.
@param socketID The socket id to be closed.
*/
void CBCloseSocket(void * socketID);