1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
< |
* s_bsd_kqueue.c: FreeBSD kqueue 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) 2005 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 |
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_kqueue.c |
23 |
> |
* \brief kqueue() compatible network routines. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
31 |
|
#include "ircd.h" |
32 |
|
#include "memory.h" |
33 |
|
#include "s_bsd.h" |
34 |
< |
#include "s_log.h" |
34 |
> |
#include "log.h" |
35 |
|
|
36 |
|
#define KE_LENGTH 128 |
37 |
|
|
51 |
|
static fde_t kqfd; |
52 |
|
static struct kevent kq_fdlist[KE_LENGTH]; /* kevent buffer */ |
53 |
|
static int kqoff; /* offset into the buffer */ |
53 |
– |
void init_netio(void); |
54 |
|
|
55 |
|
/* |
56 |
|
* init_netio |
65 |
|
|
66 |
|
if ((fd = kqueue()) < 0) |
67 |
|
{ |
68 |
< |
ilog(L_CRIT, "init_netio: Couldn't open kqueue fd!"); |
68 |
> |
ilog(LOG_TYPE_IRCD, "init_netio: Couldn't open kqueue fd!"); |
69 |
|
exit(115); /* Whee! */ |
70 |
|
} |
71 |
|
|
85 |
|
|
86 |
|
if (++kqoff == KE_LENGTH) |
87 |
|
{ |
88 |
< |
kevent(kqfd.fd, kq_fdlist, kqoff, NULL, 0, &zero_timespec); |
88 |
> |
int i; |
89 |
> |
|
90 |
> |
for (i = 0; i < kqoff; ++i) |
91 |
> |
kevent(kqfd.fd, &kq_fdlist[i], 1, NULL, 0, &zero_timespec); |
92 |
|
kqoff = 0; |
93 |
|
} |
94 |
|
} |
118 |
|
} |
119 |
|
|
120 |
|
new_events = (F->read_handler ? COMM_SELECT_READ : 0) | |
121 |
< |
(F->write_handler ? COMM_SELECT_WRITE : 0); |
121 |
> |
(F->write_handler ? COMM_SELECT_WRITE : 0); |
122 |
|
|
123 |
|
if (timeout != 0) |
124 |
+ |
{ |
125 |
|
F->timeout = CurrentTime + (timeout / 1000); |
126 |
+ |
F->timeout_handler = handler; |
127 |
+ |
F->timeout_data = client_data; |
128 |
+ |
} |
129 |
|
|
130 |
|
diff = new_events ^ F->evcache; |
131 |
|
|
183 |
|
continue; |
184 |
|
|
185 |
|
if (ke[i].filter == EVFILT_READ) |
186 |
+ |
{ |
187 |
|
if ((hdl = F->read_handler) != NULL) |
188 |
|
{ |
189 |
|
F->read_handler = NULL; |
190 |
|
hdl(F, F->read_data); |
191 |
< |
if (!F->flags.open) |
192 |
< |
continue; |
191 |
> |
if (!F->flags.open) |
192 |
> |
continue; |
193 |
|
} |
194 |
+ |
} |
195 |
|
|
196 |
|
if (ke[i].filter == EVFILT_WRITE) |
197 |
+ |
{ |
198 |
|
if ((hdl = F->write_handler) != NULL) |
199 |
|
{ |
200 |
|
F->write_handler = NULL; |
201 |
|
hdl(F, F->write_data); |
202 |
< |
if (!F->flags.open) |
203 |
< |
continue; |
202 |
> |
if (!F->flags.open) |
203 |
> |
continue; |
204 |
|
} |
205 |
+ |
} |
206 |
|
|
207 |
|
comm_setselect(F, 0, NULL, NULL, 0); |
208 |
|
} |