From a7c829df3c819020f2eccbe53452b5131757e872 Mon Sep 17 00:00:00 2001 From: hackbard Date: Fri, 8 Aug 2003 04:08:02 +0000 Subject: [PATCH] added event.c (event api) --- event.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 event.c diff --git a/event.c b/event.c new file mode 100644 index 0000000..316f0d6 --- /dev/null +++ b/event.c @@ -0,0 +1,64 @@ +/* + * event.c -- simple event api + * + * author: hackbard@hackdaworld.dyndns.org + * + */ + +#include +#include + +typedef struct __fd_list { + int fd; + unsigned char mode; + fd_list *next; +} fd_list; + +#define READ 1 +#define WRITE 2 + +int add_fd(int fd,unsigned char mode,fd_list *fd_list) { + fd_list *new; + if(fd_list->next==NULL) { + if((new=(fd_list *)(malloc(sizeof(fd_list))))==NULL) { + puts("failed allocating fd_list memory"); + return -1; + } + new->fd=fd; + new->mode=mode; + fd_list->next=new; + fd_list->next->next=NULL; + return fd; + } + else add_fd(fd,mode,tv,fd_list->next); +} + +int del_fd(int fd,fd_list *fd_list) { + fd_list *tmp; + if(fd_list->next->fd==fd) { + tmp=fd_list->next; + fd_list->next=fd_list->next->next; + free(tmp); + return fd; + } + else { + if(fd_list->next==NULL) { + puts("didnt find this fd in list!); + return -1; + } + del_fd(fd,fd_list->next); + } + return 1; +} + +get_max_fd(fd_list *fd_list) { + int test=-1; + if(fd_list->next=NULL) return test; + else { + if(fd_list->fd>test) test=fd_list->fd; + get_max_fd(fd_list->next); + } +} + +int loop(fd_list *fd_list,timeval tv) { + -- 2.20.1