Okay, I've finished off the IO completion port code. I'd appreciate feedback on the API design.
There are three functions; 1. void socket_iocp_new( void **socket_iocp_state ); This function takes a pointer to a void pointer and malloc's some memory onto it. This memory holds the state for this instance my IOCP handling object. This function also starts up a single thread (more on that later). 2. void socket_iocp_delete( void *socket_iocp_state ); This function takes an existing IOCP object and shuts it down, freeing up all resources. 3. void socket_iocp_add_socket( void *socket_iocp_state, SOCKET socket, void *user_state, size_t read_buffer_size, void (*callback_function)(void *ess, void *socket_state, int event_type, void *read_buffer, DWORD byte_count, void *user_state) ); This function passes a connected socket to an IOCP object and causes reads to begin on that socket. (The user specifies the size of the buffer to be used for reads and can pass in a pointer to his own state, which comes back to him as an argument in the callback function). The callback function is called every time a read successfully occurs. The callback function event argument is either - success/local close/remote close. The callback function provides the buffer which holds the read data and specifies the length of that data. The user does no other work - he simply passes the socket and callback function in and that's it. Everything else is automatic - his callback function will be called when things happen. To remove a socket from the IOCP object, simply call CloseHandle() on that socket. The closing of the socket handle causes the OS to remove it from the IOCP object. Note that the socket must already have been connected before being added. The thread that socket_iocp_new() starts is responsible for waiting on the IOCP object and calling the callback functions. _______________________________________________ Libevent-users mailing list Libevent-users@monkey.org http://monkey.org/mailman/listinfo/libevent-users