]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/io.c
remove unneeded call io_event_kqueue_commit_cache()
[ngircd-alex.git] / src / ngircd / io.c
index efeba72f5a2c8558cc648311168bd5acb9b92feb..7c1a55175e003be2620079dac898e7e7cc3b6339 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: io.c,v 1.1 2005/07/07 18:38:35 fw Exp $";
+static char UNUSED id[] = "$Id: io.c,v 1.6 2005/08/27 20:25:54 fw Exp $";
 
 #include <assert.h>
 #include <stdlib.h>
@@ -46,6 +46,7 @@ typedef struct {
 #endif
 #endif
 
+static bool library_initialized;
 
 #ifdef IO_USE_EPOLL
 #include <sys/epoll.h>
@@ -90,12 +91,6 @@ io_event_get(int fd)
        i = (io_event *) array_get(&io_events, sizeof(io_event), fd);
        assert(i);
 
-       if (!i) {
-#ifdef DEBUG
-               Log(LOG_DEBUG, "io_event_add(): EMPTY FOR fd %d", fd);
-#endif
-               return NULL;
-       }
        return i;
 }
 
@@ -103,12 +98,16 @@ io_event_get(int fd)
 bool
 io_library_init(unsigned int eventsize)
 {
+       bool ret;
 #ifdef IO_USE_EPOLL
        int ecreate_hint = (int)eventsize;
        if (ecreate_hint <= 0)
                ecreate_hint = 128;
 #endif
 
+       if (library_initialized)
+               return true;
+
 #ifdef IO_USE_SELECT
 #ifdef FD_SETSIZE
        if (eventsize >= FD_SETSIZE)
@@ -121,60 +120,61 @@ io_library_init(unsigned int eventsize)
 #ifdef IO_USE_EPOLL
        io_masterfd = epoll_create(ecreate_hint);
        Log(LOG_INFO,
-           "io subsystem: using epoll (hint size %d), initial io_event maxfd: %u, io_masterfd %d",
+           "IO subsystem: epoll (hint size %d, initial maxfd %u, masterfd %d).",
            ecreate_hint, eventsize, io_masterfd);
-       return io_masterfd >= 0;
+       ret = io_masterfd >= 0;
+       if (ret) library_initialized = true;
+
+       return ret;
 #endif
 #ifdef IO_USE_SELECT
-       Log(LOG_INFO, "io subsystem: using select, initial io_event maxfd: %u",
+       Log(LOG_INFO, "IO subsystem: select (initial maxfd %u).",
            eventsize);
        FD_ZERO(&readers);
        FD_ZERO(&writers);
 #ifdef FD_SETSIZE
        if (Conf_MaxConnections >= FD_SETSIZE) {
                Log(LOG_WARNING,
-                   "Conf_MaxConnections (%d) exceeds limit (%u), changed Conf_MaxConnections to %u",
+                   "MaxConnections (%d) exceeds limit (%u), changed MaxConnections to %u.",
                    Conf_MaxConnections, FD_SETSIZE, FD_SETSIZE - 1);
 
                Conf_MaxConnections = FD_SETSIZE - 1;
        }
 #else
        Log(LOG_WARNING,
-           "FD_SETSIZE undefined, don't know how many descriptors select() can handle on your platform");
-#endif
+           "FD_SETSIZE undefined, don't know how many descriptors select() can handle on your platform ...");
+#endif /* FD_SETSIZE */
+       library_initialized = true;
        return true;
-#endif
+#endif /* SELECT */
 #ifdef IO_USE_KQUEUE
        io_masterfd = kqueue();
 
        Log(LOG_INFO,
-           "io subsystem: using kqueue, initial io_event maxfd: %u, io_masterfd %d",
+           "IO subsystem: kqueue (initial maxfd %u, masterfd %d)",
            eventsize, io_masterfd);
-       return io_masterfd >= 0;
+       ret = io_masterfd >= 0;
+       if (ret) library_initialized = true;
+
+       return ret;
 #endif
 }
 
 
-bool
+void
 io_library_shutdown(void)
 {
-       unsigned int len = array_length(&io_events, sizeof(io_event));
-
-       while (len--) {
-               if (NULL == io_event_get(len))
-                       continue;
-       }
-#ifndef IO_USE_SELECT
-       close(io_masterfd);     /* kqueue, epoll */
-       io_masterfd = -1;
-#else
+#ifdef IO_USE_SELECT
        FD_ZERO(&readers);
        FD_ZERO(&writers);
+#else
+       close(io_masterfd);     /* kqueue, epoll */
+       io_masterfd = -1;
 #endif
 #ifdef IO_USE_KQUEUE
        array_free(&io_evcache);
 #endif
-       return true;
+       library_initialized = false;
 }
 
 
@@ -299,7 +299,6 @@ io_event_add_kqueue(int fd, short what)
        struct kevent kev;
        short filter = 0;
        unsigned int len = array_length(&io_evcache, sizeof kev);
-       bool ret;
 
        if (what & IO_WANTREAD)
                filter = EVFILT_READ;
@@ -308,9 +307,7 @@ io_event_add_kqueue(int fd, short what)
                filter |= EVFILT_WRITE;
 
        if (len >= 100) {
-               ret = io_event_kqueue_commit_cache();
-               if (ret)
-                       array_trunc(&io_evcache);
+               (void)array_trunc(&io_evcache);
        }
 
        EV_SET(&kev, fd, filter, EV_ADD | EV_ENABLE, 0, 0, NULL);
@@ -331,8 +328,7 @@ io_event_add(int fd, short what)
        if (i->what == what)
                return true;
 #ifdef DEBUG
-       Log(LOG_DEBUG, "io_event_add(): fd %d (arg: %d), what %d.", i->fd, fd,
-           what);
+       Log(LOG_DEBUG, "io_event_add(): fd %d (arg: %d), what %d.", i->fd, fd, what);
 #endif
 
        i->what |= what;
@@ -407,12 +403,11 @@ io_event_del(int fd, short what)
 #endif
        io_event *i = io_event_get(fd);
 #ifdef DEBUG
-       Log(LOG_DEBUG, "io_event_del(): trying to delete eventtype %d on fd %d",
-           what, fd);
+       Log(LOG_DEBUG, "io_event_del(): trying to delete eventtype %d on fd %d", what, fd);
 #endif
        assert(i);
        if (!i)
-               return true;
+               return false;
 
        i->what &= ~what;
 
@@ -526,7 +521,7 @@ io_dispatch_kqueue(struct timeval *tv)
 {
        int i, total = 0, ret;
        struct kevent kev[100];
-       struct kevents *newevents;
+       struct kevent *newevents;
        struct timespec ts;
        int newevents_len;
        short type;
@@ -544,7 +539,8 @@ io_dispatch_kqueue(struct timeval *tv)
                        assert(newevents);
 #endif
 
-               ret = kevent(io_masterfd, newevents, newevents_len, kev, 100, &ts);
+               ret = kevent(io_masterfd, newevents, newevents_len, kev,
+                            100, &ts);
                if ((newevents_len>0) && ret != -1)
                        array_trunc(&io_evcache);