Skip to content

Commit 8e9f057

Browse files
author
chris_kohlhoff
committed
Fix kqueue_reactor to work with NetBSD.
1 parent 5f0857a commit 8e9f057

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

asio/include/asio/detail/impl/kqueue_reactor.ipp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626

2727
#include "asio/detail/push_options.hpp"
2828

29+
#if defined(__NetBSD__)
30+
# define ASIO_KQUEUE_EV_SET(ev, ident, filt, flags, fflags, data, udata) \
31+
EV_SET(ev, ident, filt, flags, fflags, \
32+
data, reinterpret_cast<intptr_t>(udata))
33+
#else
34+
# define ASIO_KQUEUE_EV_SET(ev, ident, filt, flags, fflags, data, udata) \
35+
EV_SET(ev, ident, filt, flags, fflags, data, udata)
36+
#endif
37+
2938
namespace asio {
3039
namespace detail {
3140

@@ -128,17 +137,17 @@ void kqueue_reactor::start_op(int op_type, socket_type descriptor,
128137
switch (op_type)
129138
{
130139
case read_op:
131-
EV_SET(&event, descriptor, EVFILT_READ,
140+
ASIO_KQUEUE_EV_SET(&event, descriptor, EVFILT_READ,
132141
EV_ADD | EV_ONESHOT, 0, 0, descriptor_data);
133142
break;
134143
case write_op:
135-
EV_SET(&event, descriptor, EVFILT_WRITE,
144+
ASIO_KQUEUE_EV_SET(&event, descriptor, EVFILT_WRITE,
136145
EV_ADD | EV_ONESHOT, 0, 0, descriptor_data);
137146
break;
138147
case except_op:
139148
if (!descriptor_data->op_queue_[read_op].empty())
140149
return; // Already registered for read events.
141-
EV_SET(&event, descriptor, EVFILT_READ,
150+
ASIO_KQUEUE_EV_SET(&event, descriptor, EVFILT_READ,
142151
EV_ADD | EV_ONESHOT, EV_OOBAND, 0, descriptor_data);
143152
break;
144153
}
@@ -233,7 +242,7 @@ void kqueue_reactor::run(bool block, op_queue<operation>& ops)
233242
for (int i = 0; i < num_events; ++i)
234243
{
235244
int descriptor = events[i].ident;
236-
void* ptr = events[i].udata;
245+
void* ptr = reinterpret_cast<void*>(events[i].udata);
237246
if (ptr == &interrupter_)
238247
{
239248
// No need to reset the interrupter since we're leaving the descriptor
@@ -246,7 +255,11 @@ void kqueue_reactor::run(bool block, op_queue<operation>& ops)
246255

247256
// Exception operations must be processed first to ensure that any
248257
// out-of-band data is read before normal data.
258+
#if defined(__NetBSD__)
259+
static const unsigned int filter[max_ops] =
260+
#else
249261
static const int filter[max_ops] =
262+
#endif
250263
{ EVFILT_READ, EVFILT_WRITE, EVFILT_READ };
251264
for (int j = max_ops - 1; j >= 0; --j)
252265
{
@@ -281,16 +294,16 @@ void kqueue_reactor::run(bool block, op_queue<operation>& ops)
281294
{
282295
case EVFILT_READ:
283296
if (!descriptor_data->op_queue_[read_op].empty())
284-
EV_SET(&event, descriptor, EVFILT_READ,
297+
ASIO_KQUEUE_EV_SET(&event, descriptor, EVFILT_READ,
285298
EV_ADD | EV_ONESHOT, 0, 0, descriptor_data);
286299
else if (!descriptor_data->op_queue_[except_op].empty())
287-
EV_SET(&event, descriptor, EVFILT_READ,
300+
ASIO_KQUEUE_EV_SET(&event, descriptor, EVFILT_READ,
288301
EV_ADD | EV_ONESHOT, EV_OOBAND, 0, descriptor_data);
289302
else
290303
continue;
291304
case EVFILT_WRITE:
292305
if (!descriptor_data->op_queue_[write_op].empty())
293-
EV_SET(&event, descriptor, EVFILT_WRITE,
306+
ASIO_KQUEUE_EV_SET(&event, descriptor, EVFILT_WRITE,
294307
EV_ADD | EV_ONESHOT, 0, 0, descriptor_data);
295308
else
296309
continue;
@@ -321,7 +334,7 @@ void kqueue_reactor::run(bool block, op_queue<operation>& ops)
321334
void kqueue_reactor::interrupt()
322335
{
323336
struct kevent event;
324-
EV_SET(&event, interrupter_.read_descriptor(),
337+
ASIO_KQUEUE_EV_SET(&event, interrupter_.read_descriptor(),
325338
EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, &interrupter_);
326339
::kevent(kqueue_fd_, &event, 1, 0, 0, 0);
327340
}
@@ -363,6 +376,8 @@ timespec* kqueue_reactor::get_timeout(timespec& ts)
363376
} // namespace detail
364377
} // namespace asio
365378

379+
#undef ASIO_KQUEUE_EV_SET
380+
366381
#include "asio/detail/pop_options.hpp"
367382

368383
#endif // defined(ASIO_HAS_KQUEUE)

0 commit comments

Comments
 (0)