From: Florent Bruneau Date: Tue, 7 Oct 2008 20:54:31 +0000 (+0200) Subject: More explicit type for events && cleanup event_cancel. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=4066718a655683e214f3c361ac71ca4466771281;p=apps%2Fpfixtools.git More explicit type for events && cleanup event_cancel. Signed-off-by: Florent Bruneau --- diff --git a/common/server.c b/common/server.c index c3b7a2b..65e1a70 100644 --- a/common/server.c +++ b/common/server.c @@ -162,17 +162,17 @@ static int start_client(server_t *server, start_client_t starter, return 0; } -int event_register(void *data) +event_t event_register(void *data) { int fds[2]; if (pipe(fds) != 0) { UNIXERR("pipe"); - return -1; + return INVALID_EVENT; } if (setnonblock(fds[0]) != 0) { close(fds[0]); close(fds[1]); - return -1; + return INVALID_EVENT; } server_t *tmp = server_acquire(); @@ -184,7 +184,7 @@ int event_register(void *data) return tmp->fd2; } -bool event_fire(int event) +bool event_fire(event_t event) { static const char *data = ""; return write(event, data, 1) == 0; @@ -192,15 +192,15 @@ bool event_fire(int event) static bool event_cancel(int event) { - static char buff[1]; + char buff[32]; while (true) { - ssize_t res = read(event, buff, 64); + ssize_t res = read(event, buff, 32); if (res == -1 && errno != EAGAIN && errno != EINTR) { UNIXERR("read"); return false; } else if (res == -1 && errno == EINTR) { continue; - } else if (res != 1) { + } else if (res != 32) { return true; } } diff --git a/common/server.h b/common/server.h index 239ae37..28f4c35 100644 --- a/common/server.h +++ b/common/server.h @@ -39,6 +39,9 @@ #include "buffer.h" typedef struct server_t server_t; +typedef int event_t; + +#define INVALID_EVENT (-1) typedef void *(*start_listener_t)(void); typedef void (*delete_client_t)(void*); @@ -64,8 +67,8 @@ ARRAY(server_t); int start_server(int port, start_listener_t starter, delete_client_t deleter); -int event_register(void *data); -bool event_fire(int event); +event_t event_register(void *data); +bool event_fire(event_t event); int server_loop(start_client_t starter, delete_client_t deleter, run_client_t runner, event_handler_t handler,