From 17a67d9faefbff1cc7e05b82ea1981f5e14ace2c Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 26 Apr 2009 19:26:55 +0200 Subject: started to move Unix-specific networking stuff into the wolf library (out of the tests) --- tests/network/test1_unix.c | 19 +++---------------- tests/network/test2_unix.c | 15 +-------------- tests/network/test_proactor.c | 20 +++++++++++++++----- 3 files changed, 19 insertions(+), 35 deletions(-) (limited to 'tests') diff --git a/tests/network/test1_unix.c b/tests/network/test1_unix.c index 27faaaa..28a5426 100644 --- a/tests/network/test1_unix.c +++ b/tests/network/test1_unix.c @@ -14,24 +14,12 @@ #include /* for close */ #include /* for errno */ -#include /* for fcntl */ #include /* for select */ #include /* for assertions */ #include /* for signal */ #define DEBUG 0 -static bool wolf_network_sock_nonblocking( int fd ) { - int flags; - - flags = fcntl( fd, F_GETFL, 0 /* ignored */ ); - if( flags < 0 ) return false; - flags |= O_NONBLOCK; - flags = fcntl( fd, F_SETFL, flags ); - if( flags < 0 ) return false; - return true; -} - #if DEBUG static char *fd_set_to_string( fd_set *fd, int min_fd, int max_fd, char *buf, size_t buflen ) { int i; @@ -130,8 +118,7 @@ int main( int argc, char *argv[] ) { } /* set socket non-blocking for asynchronous connect */ - if( !wolf_network_sock_nonblocking( fd ) ) { - fprintf( stderr, "set nonblocking failed for socket: %s (%d)\n", strerror( errno ), errno ); + if( wolf_network_set_nonblocking( fd ) != WOLF_OK ) { goto FAIL; } @@ -245,11 +232,11 @@ CONNECTED: fprintf( stderr, "Connected to %s, port %s (peer: %s, %s)\n", host, service, peer_hostname, peer_service ); - if( !wolf_network_sock_nonblocking( STDIN_FILENO ) ) { + if( wolf_network_set_nonblocking( STDIN_FILENO ) != WOLF_OK ) { (void)close( fd ); goto FAIL; } - if( !wolf_network_sock_nonblocking( STDOUT_FILENO ) ) { + if( !wolf_network_set_nonblocking( STDOUT_FILENO ) != WOLF_OK ) { fprintf( stderr, "set nonblocking failed for stdout: %s (%d)\n", strerror( errno ), errno ); goto FAIL; } diff --git a/tests/network/test2_unix.c b/tests/network/test2_unix.c index 3964c93..dcb468c 100644 --- a/tests/network/test2_unix.c +++ b/tests/network/test2_unix.c @@ -13,7 +13,6 @@ #include /* for close */ #include /* for errno */ -#include /* for fcntl */ #include /* for select */ #include /* for assertions */ #include /* for signal */ @@ -23,17 +22,6 @@ #define MAX_ACCEPT_IDLE_TIMEOUT 4 #define MAX_IDLE_TIMEOUT 10 -static bool wolf_network_sock_nonblocking( int fd ) { - int flags; - - flags = fcntl( fd, F_GETFL, 0 /* ignored */ ); - if( flags < 0 ) return false; - flags |= O_NONBLOCK; - flags = fcntl( fd, F_SETFL, flags ); - if( flags < 0 ) return false; - return true; -} - #if DEBUG static char *fd_set_to_string( fd_set *fd, int min_fd, int max_fd, char *buf, size_t buflen ) { int i; @@ -156,8 +144,7 @@ int main( int argc, char* argv[] ) { } /* set socket non-blocking for accepts (Stevens 15.6) */ - if( !wolf_network_sock_nonblocking( serv_fd ) ) { - fprintf( stderr, "set nonblocking failed for server socket: %s (%d)\n", strerror( errno ), errno ); + if( wolf_network_set_nonblocking( serv_fd ) != WOLF_OK ) { goto FAIL; } diff --git a/tests/network/test_proactor.c b/tests/network/test_proactor.c index fc44b13..2d998cc 100644 --- a/tests/network/test_proactor.c +++ b/tests/network/test_proactor.c @@ -19,8 +19,13 @@ typedef struct wolf_asio_completion_dispatcher_t *wolf_asio_completion_dispatche * - the Acceptor: accepts new connections arsynchronously * - the Protocol Handler: handles all the communication with the * other peer, it should never do long synchronous work! + * - per operation there is one specialized handler, so we can pass + * aynchronous request data to it */ -typedef void(*wolf_asio_completion_handler_f)( void ); +typedef void(*wolf_asio_write_completion_handler_f)( void ); +typedef void(*wolf_asio_read_completion_handler_f)( void ); +typedef void(*wolf_asio_accept_completion_handler_f)( void ); +typedef void(*wolf_asio_connect_completion_handler_f)( void ); /* Asynchronous Operation Processor (asio_proc): * - performs the asynchronous opreation on behalf of the application, @@ -51,14 +56,19 @@ wolf_error_t wolf_asio_proc_free( wolf_asio_proc_p proc ); wolf_error_t wolf_asio_proc_write( wolf_asio_proc_p proc, char *buf, - size_t buflen ); + size_t buflen, + wolf_asio_write_completion_handler_f completion_handler ); wolf_error_t wolf_asio_proc_read( wolf_asio_proc_p proc, char *buf, - size_t buflen ); + size_t buflen, + wolf_asio_read_completion_handler_f completion_handler ); wolf_error_t wolf_asio_proc_accept( wolf_asio_proc_p proc, - wolf_asio_completion_handler_f completion_handler ); + wolf_asio_accept_completion_handler_f completion_handler ); + +wolf_error_t wolf_asio_proc_connect( wolf_asio_proc_p proc, + wolf_asio_connect_completion_handler_f completion_handler ); /** * Acceptor @@ -125,7 +135,7 @@ wolf_error_t wolf_asio_proc_free( wolf_asio_proc_p proc ) { } wolf_error_t wolf_asio_proc_accept( wolf_asio_proc_p proc, - wolf_asio_completion_handler_f completion_handler ) { + wolf_asio_accept_completion_handler_f completion_handler ) { WOLF_UNUSED( proc ); WOLF_UNUSED( completion_handler ); -- cgit v1.2.3-54-g00ecf