From: Toby Douglass <[EMAIL PROTECTED]>
Okay, so I've finished writing the IOCP code. I now need to finish the test/example application. When that's done, I'll upload. Might even be this weekend. Prototypes ========== 1. int socket_iocp_new( void **socket_iocp_state, size_t read_buffer_size, void (*accept_callback_function)(SOCKET socket, struct sockaddr *local_address, struct sockaddr *remote_address, void *listen_socket_user_state, void **per_socket_user_state), void (*recv_callback_function)(SOCKET socket, void *read_buffer, DWORD byte_count, void *per_socket_user_state), void (*send_callback_function)( SOCKET socket, void *per_socket_user_state, void *per_write_user_state ), void (*error_callback_function)(SOCKET socket, void *per_socket_user_state) );
[...]
Comments and thoughts, please.
It looks to me like all your callbacks are asynchronous. Is that the case? If so you're probably working off the standard iocp example code which spawns num_cpus/2 or num_cpus*2 or f(num_cpus) threads, however that's the sort of choice that I think should be left to user, exposing instead an interface int iocp_wait(long timeout) which calls the callbacks. This lets the user choose the "asynchronicity" of their app, i.e. they can write singlethreaded mutex-less iocp code. As an interface socket_iocp_new is a tiny bit "busy" as it wraps almost every function that iocps understand. A bit of factoring might make it more friendly. A control-block style interface could also help as it cuts down the argument list and makes the "per socket user state" implicit (it actually makes it per iocp operation user state). It also gives you two way communication (user -> iocp library -> user in callback) typedef struct { SOCKET s; /* <- */ char* buf; /* <-, -> */ long nbytes; /* <-, -> */ void (*iocp_read_callback)(iocp_state* st, iocp_read* control_block); /* <- */ } iocp_read; The user can piggy back per operation data like so: typedef struct { iocp_read control_block; /* extra stuff here */ }my_iocp_read; void my_iocp_read_callback)(iocp_state* st, iocp_read* control_block) { my_iocp_read* my_cb = (my_iocp_read*)control_block; /* respond, requeue, whatever */ } RF -- felix: lightweight threads, HOFs and game scripting. svn co https://svn.sourceforge.net/svnroot/felix/felix/trunk felix _______________________________________________ Libevent-users mailing list Libevent-users@monkey.org http://monkey.org/mailman/listinfo/libevent-users