ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/s_bsd_poll.c
(Generate patch)

Comparing:
ircd-hybrid/src/s_bsd_poll.c (file contents), Revision 33 by knight, Sun Oct 2 20:50:00 2005 UTC vs.
ircd-hybrid/trunk/src/s_bsd_poll.c (file contents), Revision 4461 by michael, Wed Aug 13 17:05:26 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  s_bsd_poll.c: POSIX poll() compatible network routines.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Originally by Adrian Chadd <adrian@creative.net.au>
6 < *  Copyright (C) 2002 Hybrid Development Team
4 > *  Copyright (c) 2000-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 19 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file s_bsd_poll.c
23 > * \brief POSIX poll() compatible network routines.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28 + #if USE_IOPOLL_MECHANISM == __IOPOLL_MECHANISM_POLL
29   #include <sys/poll.h>
30   #include "fdlist.h"
31 < #include "hook.h"
31 > #include "list.h"
32 > #include "memory.h"
33   #include "ircd.h"
34   #include "s_bsd.h"
35 < #include "s_log.h"
35 > #include "log.h"
36  
37   /* I hate linux -- adrian */
38   #ifndef POLLRDNORM
# Line 41 | Line 44
44  
45   static struct pollfd *pollfds;
46   static int pollmax = -1;  /* highest FD number */
44 static dlink_node *hookptr;
47  
46 /*
47 * changing_fdlimit
48 *
49 * Resize pollfds array if necessary.
50 */
51 static void *
52 changing_fdlimit(va_list args)
53 {
54  int old_fdlimit = hard_fdlimit;
55
56  pass_callback(hookptr, va_arg(args, int));
57
58  if (hard_fdlimit != old_fdlimit)
59    pollfds = MyRealloc(pollfds, sizeof(struct pollfd) * hard_fdlimit);
60
61  return NULL;
62 }
48  
49   /*
50   * init_netio
# Line 72 | Line 57 | init_netio(void)
57   {
58    int fd;
59  
60 <  pollfds = MyMalloc(sizeof(struct pollfd) * hard_fdlimit);
60 >  pollfds = MyCalloc(sizeof(struct pollfd) * hard_fdlimit);
61  
62    for (fd = 0; fd < hard_fdlimit; fd++)
63      pollfds[fd].fd = -1;
79
80  hookptr = install_hook(fdlimit_cb, changing_fdlimit);
64   }
65  
66   /*
# Line 108 | Line 91 | poll_findslot(void)
91   * and deregister interest in a pending IO state for a given FD.
92   */
93   void
94 < comm_setselect(fde_t *F, unsigned int type, PF *handler,
94 > comm_setselect(fde_t *F, unsigned int type, void (*handler)(fde_t *, void *),
95                 void *client_data, time_t timeout)
96 < {  
96 > {
97    int new_events;
98  
99    if ((type & COMM_SELECT_READ))
# Line 126 | Line 109 | comm_setselect(fde_t *F, unsigned int ty
109    }
110  
111    new_events = (F->read_handler ? POLLRDNORM : 0) |
112 <    (F->write_handler ? POLLWRNORM : 0);
112 >               (F->write_handler ? POLLWRNORM : 0);
113  
114    if (timeout != 0)
115 +  {
116      F->timeout = CurrentTime + (timeout / 1000);
117 +    F->timeout_handler = handler;
118 +    F->timeout_data = client_data;
119 +  }
120  
121    if (new_events != F->evcache)
122    {
# Line 140 | Line 127 | comm_setselect(fde_t *F, unsigned int ty
127  
128        if (pollmax == F->comm_index)
129          while (pollmax >= 0 && pollfds[pollmax].fd == -1)
130 <          pollmax--;
130 >          pollmax--;
131      }
132      else
133      {
134        if (F->evcache == 0)
135        {
136          F->comm_index = poll_findslot();
137 <        if (F->comm_index > pollmax)
138 <          pollmax = F->comm_index;
137 >        if (F->comm_index > pollmax)
138 >          pollmax = F->comm_index;
139  
140 <        pollfds[F->comm_index].fd = F->fd;
140 >        pollfds[F->comm_index].fd = F->fd;
141        }
142 +
143        pollfds[F->comm_index].events = new_events;
144        pollfds[F->comm_index].revents = 0;
145      }
# Line 159 | Line 147 | comm_setselect(fde_t *F, unsigned int ty
147      F->evcache = new_events;
148    }
149   }
150 <
150 >
151   /*
152   * comm_select
153   *
# Line 172 | Line 160 | void
160   comm_select(void)
161   {
162    int num, ci, revents;
163 <  PF *hdl;
163 >  void (*hdl)(fde_t *, void *);
164    fde_t *F;
165  
166    /* XXX kill that +1 later ! -- adrian */
# Line 199 | Line 187 | comm_select(void)
187        continue;
188  
189      if (revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR))
190 +    {
191        if ((hdl = F->read_handler) != NULL)
192        {
193          F->read_handler = NULL;
194          hdl(F, F->read_data);
195 <        if (!F->flags.open)
196 <          continue;
195 >        if (!F->flags.open)
196 >          continue;
197        }
198 +    }
199  
200      if (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR))
201 +    {
202        if ((hdl = F->write_handler) != NULL)
203        {
204          F->write_handler = NULL;
205          hdl(F, F->write_data);
206 <        if (!F->flags.open)
207 <          continue;
206 >        if (!F->flags.open)
207 >          continue;
208        }
209 +    }
210  
211      comm_setselect(F, 0, NULL, NULL, 0);
212    }
213   }
214 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)