]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/io.c
New configuration option "SyslogFacility"
[ngircd-alex.git] / src / ngircd / io.c
index 34066b2b3958928910e588cf6ba879b99caeb722..6843899d5b61e280895e20577072c98282b464f9 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: io.c,v 1.29 2008/03/27 15:47:21 fw Exp $";
+static char UNUSED id[] = "$Id: io.c,v 1.31 2008/04/03 20:56:44 fw Exp $";
 
 #include <assert.h>
 #include <stdlib.h>
@@ -104,13 +104,17 @@ static bool io_event_change_devpoll(int fd, short what);
 
 #ifdef IO_USE_SELECT
 #include "defines.h"   /* for conn.h */
-#include "conn.h"      /* for CONN_IDX (needed by resolve.h) */
-#include "resolve.h"   /* for RES_STAT (needed by conf.h) */
+#include "proc.h"      /* for PROC_STAT (needed by conf.h) */
+#include "conn.h"      /* for CONN_ID (needed by conf.h) */
 #include "conf.h"      /* for Conf_MaxConnections */
 
 static fd_set readers;
 static fd_set writers;
-static int select_maxfd;               /* the select() interface sucks badly */
+/*
+ * this is the first argument for select(), i.e.
+ * the largest fd registered, plus one.
+ */
+static int select_maxfd;
 static int io_dispatch_select(struct timeval *tv);
 
 #ifndef IO_USE_EPOLL
@@ -384,6 +388,9 @@ io_library_init_select(unsigned int eventsize)
 
                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 */
        library_initialized = true;
 }
@@ -622,15 +629,7 @@ io_library_init(unsigned int eventsize)
 {
        if (library_initialized)
                return true;
-#ifdef IO_USE_SELECT
-#ifndef FD_SETSIZE
-       Log(LOG_WARNING,
-           "FD_SETSIZE undefined, don't know how many descriptors select() can handle on your platform ...");
-#else
-       if (eventsize >= FD_SETSIZE)
-               eventsize = FD_SETSIZE - 1;
-#endif /* FD_SETSIZE */
-#endif /* IO_USE_SELECT */
+
        if ((eventsize > 0) && !array_alloc(&io_events, sizeof(io_event), (size_t)eventsize))
                eventsize = 0;
 
@@ -707,7 +706,7 @@ io_event_create(int fd, short what, void (*cbfunc) (int, short))
 
        assert(fd >= 0);
 #if defined(IO_USE_SELECT) && defined(FD_SETSIZE)
-       if (fd >= FD_SETSIZE) {
+       if (io_masterfd < 0 && fd >= FD_SETSIZE) {
                Log(LOG_ERR,
                    "fd %d exceeds FD_SETSIZE (%u) (select can't handle more file descriptors)",
                    fd, FD_SETSIZE);
@@ -786,6 +785,16 @@ io_setnonblock(int fd)
        return fcntl(fd, F_SETFL, flags) == 0;
 }
 
+bool
+io_setcloexec(int fd)
+{
+       int flags = fcntl(fd, F_GETFD);
+       if (flags == -1)
+               return false;
+       flags |= FD_CLOEXEC;
+
+       return fcntl(fd, F_SETFD, flags) == 0;
+}
 
 bool
 io_close(int fd)