1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
< |
* s_bsd_devpoll.c: /dev/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) 2001-2016 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 |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU General Public License |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
|
* USA |
20 |
< |
* |
21 |
< |
* $Id$ |
20 |
> |
*/ |
21 |
> |
|
22 |
> |
/*! \file s_bsd_devpoll.c |
23 |
> |
* \brief /dev/poll compatible network routines. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
40 |
|
#include "fdlist.h" |
41 |
|
#include "ircd.h" |
42 |
|
#include "s_bsd.h" |
43 |
< |
#include "s_log.h" |
43 |
> |
#include "log.h" |
44 |
|
|
45 |
|
static fde_t dpfd; |
46 |
|
|
57 |
|
|
58 |
|
if ((fd = open("/dev/poll", O_RDWR)) < 0) |
59 |
|
{ |
60 |
< |
ilog(L_CRIT, "init_netio: Couldn't open /dev/poll - %d: %s", |
61 |
< |
errno, strerror(errno)); |
62 |
< |
exit(115); /* Whee! */ |
60 |
> |
ilog(LOG_TYPE_IRCD, "init_netio: couldn't open /dev/poll: %s", |
61 |
> |
strerror(errno)); |
62 |
> |
exit(EXIT_FAILURE); /* Whee! */ |
63 |
|
} |
64 |
|
|
65 |
|
fd_open(&dpfd, fd, 0, "/dev/poll file descriptor"); |
83 |
|
|
84 |
|
/* Write the thing to our poll fd */ |
85 |
|
if (write(dpfd.fd, &pfd, sizeof(pfd)) != sizeof(pfd)) |
86 |
< |
ilog(L_NOTICE, "devpoll_write_update: dpfd write failed %d: %s", |
86 |
> |
ilog(LOG_TYPE_IRCD, "devpoll_write_update: dpfd write failed %d: %s", |
87 |
|
errno, strerror(errno)); |
88 |
|
} |
89 |
|
|
94 |
|
* and deregister interest in a pending IO state for a given FD. |
95 |
|
*/ |
96 |
|
void |
97 |
< |
comm_setselect(fde_t *F, unsigned int type, PF *handler, |
97 |
> |
comm_setselect(fde_t *F, unsigned int type, void (*handler)(fde_t *, void *), |
98 |
|
void *client_data, time_t timeout) |
99 |
|
{ |
100 |
|
int new_events; |
115 |
|
(F->write_handler ? POLLOUT : 0); |
116 |
|
|
117 |
|
if (timeout != 0) |
118 |
+ |
{ |
119 |
|
F->timeout = CurrentTime + (timeout / 1000); |
120 |
+ |
F->timeout_handler = handler; |
121 |
+ |
F->timeout_data = client_data; |
122 |
+ |
} |
123 |
|
|
124 |
|
if (new_events != F->evcache) |
125 |
|
{ |
143 |
|
int num, i; |
144 |
|
struct pollfd pollfds[128]; |
145 |
|
struct dvpoll dopoll; |
146 |
< |
PF *hdl; |
146 |
> |
void (*hdl)(fde_t *, void *); |
147 |
|
fde_t *F; |
148 |
|
|
149 |
|
dopoll.dp_timeout = SELECT_DELAY; |
155 |
|
|
156 |
|
if (num < 0) |
157 |
|
{ |
158 |
< |
#ifdef HAVE_USLEEP |
159 |
< |
usleep(50000); /* avoid 99% CPU in comm_select */ |
155 |
< |
#endif |
158 |
> |
const struct timespec req = { .tv_sec = 0, .tv_nsec = 50000000 }; |
159 |
> |
nanosleep(&req, NULL); /* Avoid 99% CPU in comm_select */ |
160 |
|
return; |
161 |
|
} |
162 |
|
|
167 |
|
continue; |
168 |
|
|
169 |
|
if ((dopoll.dp_fds[i].revents & POLLIN)) |
170 |
+ |
{ |
171 |
|
if ((hdl = F->read_handler) != NULL) |
172 |
|
{ |
173 |
|
F->read_handler = NULL; |
175 |
|
if (!F->flags.open) |
176 |
|
continue; |
177 |
|
} |
178 |
+ |
} |
179 |
|
|
180 |
|
if ((dopoll.dp_fds[i].revents & POLLOUT)) |
181 |
< |
if ((hdl = F->write_handler) != NULL) |
181 |
> |
{ |
182 |
> |
if ((hdl = F->write_handler) != NULL) |
183 |
|
{ |
184 |
|
F->write_handler = NULL; |
185 |
|
hdl(F, F->write_data); |
186 |
|
if (!F->flags.open) |
187 |
|
continue; |
188 |
|
} |
189 |
+ |
} |
190 |
|
|
191 |
|
comm_setselect(F, 0, NULL, NULL, 0); |
192 |
|
} |