From e2af183ea7e5ea35a1582f40a01a7c49e83b31be Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 15 Jan 2009 23:19:58 +0100 Subject: sync: unify tx_list and tx_queue into one single tx_queue This patch unifies the tx_list and the tx_queue to have only one transmission queue. Since the tx_list hold state objects and tx_queue control messages, I have introduced a queue node type that can be used to differenciate the kind of information that the node stores: object or control message. This patch also reworks the existing queue class to include a file descriptor that can be used to know if there are new data added to the queue (see QUEUE_F_EVFD flag). In this change, I have also modified the current evfd to make the file descriptor to make read operations non-blocking. Moreover, it keeps a counter that is used to know how many messages are inserted in the queue. Signed-off-by: Pablo Neira Ayuso --- src/event.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/event.c') diff --git a/src/event.c b/src/event.c index ed78835..d1dfe72 100644 --- a/src/event.c +++ b/src/event.c @@ -17,6 +17,8 @@ */ #include #include +#include +#include #include "event.h" @@ -37,6 +39,7 @@ struct evfd *create_evfd(void) free(e); return NULL; } + fcntl(e->fds[0], F_SETFL, O_NONBLOCK); return e; } @@ -55,19 +58,20 @@ int get_read_evfd(struct evfd *evfd) int write_evfd(struct evfd *evfd) { - int data = 0; + int data = 0, ret = 0; - if (evfd->read) - return 0; + if (evfd->read == 0) + ret = write(evfd->fds[1], &data, sizeof(data)); + evfd->read++; - evfd->read = 1; - return write(evfd->fds[1], &data, sizeof(data)); + return ret; } int read_evfd(struct evfd *evfd) { - int data; + int data, ret = 0; - evfd->read = 0; - return read(evfd->fds[0], &data, sizeof(data)); + if (--evfd->read == 0) + ret = read(evfd->fds[0], &data, sizeof(data)); + return ret; } -- cgit v1.2.3