From 325b1b51c15029b1a460df49bcfff6844dbc2328 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 31 Dec 2014 14:08:20 +0000 Subject: [PATCH] - irc.c:irc_cycle(): replaced select() with poll() git-svn-id: svn://svn.ircd-hybrid.org/svnroot/hopm/branches/1.0.x@5225 82007160-df01-0410-b94d-b575c5fd34c7 --- src/irc.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/irc.c b/src/irc.c index d6a534f..9719338 100644 --- a/src/irc.c +++ b/src/irc.c @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef TIME_WITH_SYS_TIME # include @@ -97,9 +98,6 @@ static int IRC_FD = 0; /* File descriptor for IRC clie static struct bopm_sockaddr IRC_SVR; /* Sock Address Struct for IRC server */ static struct bopm_ircaddr IRC_LOCAL; /* Sock Address Struct for Bind */ -static fd_set IRC_READ_FDSET; /* fd_set for IRC (read) data for select()*/ -static struct timeval IRC_TIMEOUT; /* timeval struct for select() timeout */ - static time_t IRC_LAST = 0; /* Last full line of data from irc server*/ static time_t IRC_LASTRECONNECT = 0; /* Time of last reconnection */ @@ -136,6 +134,8 @@ static struct CommandHash COMMAND_TABLE[] = void irc_cycle(void) { + static struct pollfd pfd; + if (IRC_FD <= 0) { /* Initialise negative cache. */ @@ -150,24 +150,18 @@ irc_cycle(void) return; /* In case connect() immediately failed */ } - IRC_TIMEOUT.tv_sec = 0; - - /* Block .025 seconds to avoid excessive CPU use on select(). */ - IRC_TIMEOUT.tv_usec = 25000; + pfd.fd = IRC_FD; + pfd.events = POLLIN; - FD_ZERO(&IRC_READ_FDSET); - FD_SET(IRC_FD, &IRC_READ_FDSET); - - switch (select((IRC_FD + 1), &IRC_READ_FDSET, 0, 0, &IRC_TIMEOUT)) + /* Block .025 seconds to avoid excessive CPU use on poll(). */ + switch (poll(&pfd, 1, 25)) { + case 0: case -1: - return; - break; - case 0: break; default: /* Check if IRC data is available. */ - if (FD_ISSET(IRC_FD, &IRC_READ_FDSET)) + if (pfd.revents & POLLIN) irc_read(); break; -- 2.30.2