X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fngircd%2Fio.c;h=037c4afca2af7c0cf9662058ee2a18d3a92b12eb;hb=7d7eb735f0c8b541e7809a68cb49174605147904;hp=f061ce057203bbd395af33102dafd3c9fb37c782;hpb=c7dd5ea0baeff589a569cdc7ffd46fc83e885ab2;p=ngircd-alex.git diff --git a/src/ngircd/io.c b/src/ngircd/io.c index f061ce05..037c4afc 100644 --- a/src/ngircd/io.c +++ b/src/ngircd/io.c @@ -1,11 +1,13 @@ /* + * ngIRCd -- The Next Generation IRC Daemon + * Copyright (c)2005-2006 Florian Westphal (westphal@foo.fh-furtwangen.de) + * Copyright (c)2006-2014 Alexander Barton (alex@barton.de) and Contributors. + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. - * - * Copyright (c) 2005 Florian Westphal (westphal@foo.fh-furtwangen.de) */ #include "portab.h" @@ -15,21 +17,20 @@ * I/O abstraction interface. */ +/* Extra debug messages in event add/delete/callback code: 0=off / 1=on */ +#define DEBUG_IO 0 + #include -#include #include -#include #include #include +#include #include #include "array.h" #include "io.h" #include "log.h" -/* Enables extra debug messages in event add/delete/callback code. */ -/* #define DEBUG_IO */ - typedef struct { #ifdef PROTOTYPES void (*callback)(int, short); @@ -41,6 +42,7 @@ typedef struct { #define INIT_IOEVENT { NULL, -1, 0, NULL } #define IO_ERROR 4 +#define MAX_EVENTS 100 #ifdef HAVE_EPOLL_CREATE # define IO_USE_EPOLL 1 @@ -85,6 +87,20 @@ static int io_masterfd; static int io_dispatch_kqueue(struct timeval *tv); static bool io_event_change_kqueue(int, short, const int action); + +#ifndef EV_SET +/* Taken from /usr/include/sys/event.h of FreeBSD 8.1 and required by all + * platforms that have kqueue but lack EV_SET() -- for example FreeBSD 4. */ +#define EV_SET(kevp, a, b, c, d, e, f) do { \ + struct kevent *__kevp__ = (kevp); \ + __kevp__->ident = (a); \ + __kevp__->filter = (b); \ + __kevp__->flags = (c); \ + __kevp__->fflags = (d); \ + __kevp__->data = (e); \ + __kevp__->udata = (f); \ +} while(0) +#endif #endif #ifdef IO_USE_POLL @@ -104,6 +120,7 @@ static bool io_event_change_devpoll(int fd, short what); #endif #ifdef IO_USE_SELECT +#include #include "defines.h" /* for conn.h */ #include "proc.h" /* for PROC_STAT (needed by conf.h) */ #include "conn.h" /* for CONN_ID (needed by conf.h) */ @@ -127,7 +144,7 @@ static array io_events; static void io_docallback PARAMS((int fd, short what)); -#ifdef DEBUG_IO +#if DEBUG_IO static void io_debug(const char *s, int fd, int what) { @@ -162,13 +179,13 @@ io_dispatch_devpoll(struct timeval *tv) time_t sec = tv->tv_sec * 1000; int i, ret, timeout = tv->tv_usec + sec; short what; - struct pollfd p[100]; + struct pollfd p[MAX_EVENTS]; if (timeout < 0) timeout = 1000; dvp.dp_timeout = timeout; - dvp.dp_nfds = 100; + dvp.dp_nfds = MAX_EVENTS; dvp.dp_fds = p; ret = ioctl(io_masterfd, DP_POLL, &dvp); @@ -458,13 +475,13 @@ io_dispatch_epoll(struct timeval *tv) { time_t sec = tv->tv_sec * 1000; int i, ret, timeout = tv->tv_usec + sec; - struct epoll_event epoll_ev[100]; + struct epoll_event epoll_ev[MAX_EVENTS]; short type; if (timeout < 0) timeout = 1000; - ret = epoll_wait(io_masterfd, epoll_ev, 100, timeout); + ret = epoll_wait(io_masterfd, epoll_ev, MAX_EVENTS, timeout); for (i = 0; i < ret; i++) { type = 0; @@ -565,7 +582,7 @@ static int io_dispatch_kqueue(struct timeval *tv) { int i, ret; - struct kevent kev[100]; + struct kevent kev[MAX_EVENTS]; struct kevent *newevents; struct timespec ts; int newevents_len; @@ -576,7 +593,7 @@ io_dispatch_kqueue(struct timeval *tv) newevents = (newevents_len > 0) ? array_start(&io_evcache) : NULL; assert(newevents_len >= 0); - ret = kevent(io_masterfd, newevents, newevents_len, kev, 100, &ts); + ret = kevent(io_masterfd, newevents, newevents_len, kev, MAX_EVENTS, &ts); if (newevents && ret != -1) array_trunc(&io_evcache); @@ -616,7 +633,7 @@ io_library_init_kqueue(unsigned int eventsize) io_masterfd = kqueue(); Log(LOG_INFO, - "IO subsystem: kqueue (initial maxfd %u, masterfd %d)", + "IO subsystem: kqueue (initial maxfd %u, masterfd %d).", eventsize, io_masterfd); if (io_masterfd >= 0) library_initialized = true;