/[svn]/hopm/branches/1.0.x/src/irc.c
ViewVC logotype

Diff of /hopm/branches/1.0.x/src/irc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5224 by michael, Mon Dec 29 19:52:01 2014 UTC revision 5225 by michael, Wed Dec 31 14:08:20 2014 UTC
# Line 31  Line 31 
31  #include <sys/socket.h>  #include <sys/socket.h>
32  #include <netinet/in.h>  #include <netinet/in.h>
33  #include <arpa/inet.h>  #include <arpa/inet.h>
34    #include <poll.h>
35    
36  #ifdef TIME_WITH_SYS_TIME  #ifdef TIME_WITH_SYS_TIME
37  # include <sys/time.h>  # include <sys/time.h>
# Line 97  static int           IRC_FD         = 0; Line 98  static int           IRC_FD         = 0;
98  static struct bopm_sockaddr IRC_SVR;             /* Sock Address Struct for IRC server    */  static struct bopm_sockaddr IRC_SVR;             /* Sock Address Struct for IRC server    */
99  static struct bopm_ircaddr  IRC_LOCAL;           /* Sock Address Struct for Bind          */  static struct bopm_ircaddr  IRC_LOCAL;           /* Sock Address Struct for Bind          */
100    
 static fd_set        IRC_READ_FDSET;             /* fd_set for IRC (read) data for select()*/  
 static struct timeval IRC_TIMEOUT;               /* timeval struct for select() timeout   */  
   
101  static time_t IRC_LAST = 0;                      /* Last full line of data from irc server*/  static time_t IRC_LAST = 0;                      /* Last full line of data from irc server*/
102  static time_t IRC_LASTRECONNECT = 0;             /* Time of last reconnection */  static time_t IRC_LASTRECONNECT = 0;             /* Time of last reconnection */
103    
# Line 136  static struct CommandHash COMMAND_TABLE[ Line 134  static struct CommandHash COMMAND_TABLE[
134  void  void
135  irc_cycle(void)  irc_cycle(void)
136  {  {
137      static struct pollfd pfd;
138    
139    if (IRC_FD <= 0)    if (IRC_FD <= 0)
140    {    {
141      /* Initialise negative cache. */      /* Initialise negative cache. */
# Line 150  irc_cycle(void) Line 150  irc_cycle(void)
150      return;  /* In case connect() immediately failed */      return;  /* In case connect() immediately failed */
151    }    }
152    
153    IRC_TIMEOUT.tv_sec  = 0;    pfd.fd = IRC_FD;
154      pfd.events = POLLIN;
   /* Block .025 seconds to avoid excessive CPU use on select(). */  
   IRC_TIMEOUT.tv_usec = 25000;  
155    
156    FD_ZERO(&IRC_READ_FDSET);    /* Block .025 seconds to avoid excessive CPU use on poll(). */
157    FD_SET(IRC_FD, &IRC_READ_FDSET);    switch (poll(&pfd, 1, 25))
   
   switch (select((IRC_FD + 1), &IRC_READ_FDSET, 0, 0, &IRC_TIMEOUT))  
158    {    {
159        case  0:
160      case -1:      case -1:
       return;  
       break;  
     case 0:  
161        break;        break;
162      default:      default:
163        /* Check if IRC data is available. */        /* Check if IRC data is available. */
164        if (FD_ISSET(IRC_FD, &IRC_READ_FDSET))        if (pfd.revents & POLLIN)
165          irc_read();          irc_read();
166    
167        break;        break;

Legend:
Removed from v.5224  
changed lines
  Added in v.5225

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28