]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/io.c
Conn_Write(): Make sure there is a client when detecting its type
[ngircd-alex.git] / src / ngircd / io.c
index 6843899d5b61e280895e20577072c98282b464f9..f44dfbf54d9f945d6f840845ae3f0cb091744845 100644 (file)
@@ -5,14 +5,15 @@
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
  *
- * I/O abstraction interface.
  * Copyright (c) 2005 Florian Westphal (westphal@foo.fh-furtwangen.de)
- *
  */
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: io.c,v 1.31 2008/04/03 20:56:44 fw Exp $";
+/**
+ * @file
+ * I/O abstraction interface.
+ */
 
 #include <assert.h>
 #include <stdlib.h>
@@ -53,7 +54,7 @@ typedef struct {
 #    ifdef HAVE_SYS_DEVPOLL_H
 #      define IO_USE_DEVPOLL   1
 #    else
-#      ifdef HAVE_POLL
+#      if defined(HAVE_POLL) && defined(HAVE_POLL_H)
 #        define IO_USE_POLL    1
 #      else
 #        ifdef HAVE_SELECT
@@ -115,7 +116,7 @@ static fd_set writers;
  * the largest fd registered, plus one.
  */
 static int select_maxfd;
-static int io_dispatch_select(struct timeval *tv);
+static int io_dispatch_select PARAMS((struct timeval *tv));
 
 #ifndef IO_USE_EPOLL
 #define io_masterfd -1
@@ -127,12 +128,15 @@ static array io_events;
 static void io_docallback PARAMS((int fd, short what));
 
 #ifdef DEBUG_IO
-static void io_debug(const char *s, int fd, int what)
+static void
+io_debug(const char *s, int fd, int what)
 {
        Log(LOG_DEBUG, "%s: %d, %d\n", s, fd, what);
 }
 #else
-static inline void io_debug(const char UNUSED *s,int UNUSED a, int UNUSED b) {/*NOTHING*/}
+static inline void
+io_debug(const char UNUSED *s,int UNUSED a, int UNUSED b)
+{ /* NOTHING */ }
 #endif
 
 static io_event *
@@ -227,8 +231,12 @@ io_library_init_devpoll(unsigned int eventsize)
                eventsize, io_masterfd);
 }
 #else
-static inline void io_close_devpoll(int UNUSED x) {/* NOTHING */}
-static inline void io_library_init_devpoll(unsigned int UNUSED ev) {/*NOTHING*/}
+static inline void
+io_close_devpoll(int UNUSED x)
+{ /* NOTHING */ }
+static inline void
+io_library_init_devpoll(unsigned int UNUSED ev)
+{ /* NOTHING */ }
 #endif
 
 
@@ -331,8 +339,12 @@ io_library_init_poll(unsigned int eventsize)
        }
 }
 #else
-static inline void io_close_poll(int UNUSED x) {/* NOTHING */}
-static inline void io_library_init_poll(unsigned int UNUSED ev) {/*NOTHING*/}
+static inline void
+io_close_poll(int UNUSED x)
+{ /* NOTHING */ }
+static inline void
+io_library_init_poll(unsigned int UNUSED ev)
+{ /* NOTHING */ }
 #endif
 
 
@@ -340,11 +352,15 @@ static inline void io_library_init_poll(unsigned int UNUSED ev) {/*NOTHING*/}
 static int
 io_dispatch_select(struct timeval *tv)
 {
-       fd_set readers_tmp = readers;
-       fd_set writers_tmp = writers;
+       fd_set readers_tmp;
+       fd_set writers_tmp;
        short what;
        int ret, i;
        int fds_ready;
+
+       readers_tmp = readers;
+       writers_tmp = writers;
+
        ret = select(select_maxfd + 1, &readers_tmp, &writers_tmp, NULL, tv);
        if (ret <= 0)
                return ret;
@@ -418,8 +434,12 @@ io_close_select(int fd)
        }
 }
 #else
-static inline void io_library_init_select(int UNUSED x) {/* NOTHING */}
-static inline void io_close_select(int UNUSED x) {/* NOTHING */}
+static inline void
+io_library_init_select(int UNUSED x)
+{ /* NOTHING */ }
+static inline void
+io_close_select(int UNUSED x)
+{ /* NOTHING */ }
 #endif /* SELECT */
 
 
@@ -494,7 +514,9 @@ io_library_init_epoll(unsigned int eventsize)
 #endif
 }
 #else
-static inline void io_library_init_epoll(unsigned int UNUSED ev) {/* NOTHING */}
+static inline void
+io_library_init_epoll(unsigned int UNUSED ev)
+{ /* NOTHING */ }
 #endif /* IO_USE_EPOLL */
 
 
@@ -620,7 +642,9 @@ io_library_init_kqueue(unsigned int eventsize)
                library_initialized = true;
 }
 #else
-static inline void io_library_init_kqueue(unsigned int UNUSED ev) {/* NOTHING */}
+static inline void
+io_library_init_kqueue(unsigned int UNUSED ev)
+{ /* NOTHING */ }
 #endif
 
 
@@ -791,7 +815,9 @@ io_setcloexec(int fd)
        int flags = fcntl(fd, F_GETFD);
        if (flags == -1)
                return false;
+#ifdef FD_CLOEXEC
        flags |= FD_CLOEXEC;
+#endif
 
        return fcntl(fd, F_SETFD, flags) == 0;
 }