41 #if defined(__APPLE__) || defined(__FreeBSD__)
42 #include <sys/event.h>
43 #elif defined(__sun__)
44 #include <sys/types.h>
45 #include <sys/socket.h>
52 #define HANDLE_POLL_INTERFACE_MODIFY \
53 if (ReactorFactory::use_poll) \
54 return m_reactor->modify_poll_interest(m_sd, poll_events(m_poll_interest));
56 #define HANDLE_POLL_INTERFACE_ADD \
57 if (ReactorFactory::use_poll) \
58 return m_reactor->add_poll_interest(m_sd, poll_events(m_poll_interest), this);
64 if (event->revents & POLLIN)
65 strcat(buf,
"POLLIN ");
66 if (event->revents & POLLRDNORM)
67 strcat(buf,
"POLLRDNORM ");
68 if (event->revents & POLLRDBAND)
69 strcat(buf,
"POLLRDBAND ");
70 if (event->revents & POLLPRI)
71 strcat(buf,
"POLLPRI ");
72 if (event->revents & POLLOUT)
73 strcat(buf,
"POLLOUT ");
74 if (event->revents & POLLWRNORM)
75 strcat(buf,
"POLLWRNORM ");
76 if (event->revents & POLLWRBAND)
77 strcat(buf,
"POLLWRBAND ");
78 if (event->revents & POLLERR)
79 strcat(buf,
"POLLERR ");
80 if (event->revents & POLLHUP)
81 strcat(buf,
"POLLHUP ");
82 if (event->revents & POLLNVAL)
83 strcat(buf,
"POLLNVAL ");
86 sprintf(buf,
"0x%x ", event->revents);
88 clog <<
"poll events = " << buf << endl;
93 m_poll_interest = mode;
94 return m_reactor->add_poll_interest(m_sd, poll_events(mode),
this);
96 #if defined(__APPLE__) || defined(__sun__) || defined(__FreeBSD__)
97 return add_poll_interest(mode);
98 #elif defined(__linux__)
99 struct epoll_event event;
100 memset(&event, 0,
sizeof(
struct epoll_event));
101 event.data.ptr =
this;
103 event.events |= EPOLLIN;
105 event.events |= EPOLLOUT;
107 event.events |= POLLRDHUP | EPOLLET;
108 m_poll_interest = mode;
109 if (epoll_ctl(m_reactor->poll_fd, EPOLL_CTL_ADD, m_sd, &event) < 0) {
110 HT_DEBUGF(
"epoll_ctl(%d, EPOLL_CTL_ADD, %d, %x) failed : %s",
111 m_reactor->poll_fd, m_sd, event.events, strerror(errno));
119 #if defined(__linux__)
123 m_poll_interest |= mode;
128 struct epoll_event event;
130 memset(&event, 0,
sizeof(
struct epoll_event));
131 event.data.ptr =
this;
134 event.events |= EPOLLIN;
136 event.events |= EPOLLOUT;
138 if (epoll_ctl(m_reactor->poll_fd, EPOLL_CTL_MOD, m_sd, &event) < 0) {
139 HT_DEBUGF(
"epoll_ctl(%d, EPOLL_CTL_MOD, sd=%d) (mode=%x, interest=%x) : %s",
140 m_reactor->poll_fd, m_sd, mode, m_poll_interest, strerror(errno));
150 m_poll_interest &= ~mode;
155 struct epoll_event event;
157 memset(&event, 0,
sizeof(
struct epoll_event));
158 event.data.ptr =
this;
160 if (m_poll_interest & PollEvent::READ)
161 event.events |= EPOLLIN;
162 if (m_poll_interest & PollEvent::WRITE)
163 event.events |= EPOLLOUT;
165 if (epoll_ctl(m_reactor->poll_fd, EPOLL_CTL_MOD, m_sd, &event) < 0) {
166 HT_DEBUGF(
"epoll_ctl(EPOLL_CTL_MOD, sd=%d) (mode=%x) : %s",
167 m_sd, mode, strerror(errno));
180 if (event->events & EPOLLIN)
181 strcat(buf,
"EPOLLIN ");
182 else if (event->events & EPOLLOUT)
183 strcat(buf,
"EPOLLOUT ");
184 else if (event->events & EPOLLPRI)
185 strcat(buf,
"EPOLLPRI ");
186 else if (event->events & EPOLLERR)
187 strcat(buf,
"EPOLLERR ");
188 else if (event->events & EPOLLHUP)
189 strcat(buf,
"EPOLLHUP ");
191 strcat(buf,
"POLLRDHUP ");
192 else if (event->events & EPOLLET)
193 strcat(buf,
"EPOLLET ");
194 #if defined(EPOLLONESHOT)
195 else if (event->events & EPOLLONESHOT)
196 strcat(buf,
"EPOLLONESHOT ");
200 sprintf(buf,
"0x%x ", event->events);
202 clog <<
"epoll events = " << buf << endl;
207 #elif defined(__sun__)
212 m_poll_interest |= mode;
216 if (m_poll_interest & PollEvent::WRITE)
219 if (m_poll_interest & PollEvent::READ)
223 if (port_associate(m_reactor->poll_fd, PORT_SOURCE_FD,
224 m_sd, events,
this) < 0) {
225 HT_DEBUGF(
"port_associate(%d, POLLIN, %d) - %s", m_reactor->poll_fd, m_sd,
236 if ((m_poll_interest & mode) == 0)
239 m_poll_interest &= ~mode;
244 error = reset_poll_interest();
246 if (port_dissociate(m_reactor->poll_fd, PORT_SOURCE_FD, m_sd) < 0) {
247 HT_DEBUGF(
"port_dissociate(%d, PORT_SOURCE_FD, %d) - %s",
248 m_reactor->poll_fd, m_sd, strerror(errno));
260 if (event->portev_events & POLLIN)
261 strcat(buf,
"POLLIN ");
262 if (event->portev_events & POLLPRI)
263 strcat(buf,
"POLLPRI ");
264 if (event->portev_events & POLLOUT)
265 strcat(buf,
"POLLOUT ");
266 if (event->portev_events & POLLRDNORM)
267 strcat(buf,
"POLLRDNORM ");
268 if (event->portev_events & POLLRDBAND)
269 strcat(buf,
"POLLRDBAND ");
270 if (event->portev_events & POLLWRBAND)
271 strcat(buf,
"POLLWRBAND ");
272 if (event->portev_events & POLLERR)
273 strcat(buf,
"POLLERR ");
274 if (event->portev_events & POLLHUP)
275 strcat(buf,
"POLLHUP ");
276 if (event->portev_events & POLLNVAL)
277 strcat(buf,
"POLLNVAL ");
278 if (event->portev_events & POLLREMOVE)
279 strcat(buf,
"POLLREMOVE ");
282 sprintf(buf,
"0x%x ", event->portev_events);
284 clog <<
"port events = " << buf << endl;
288 #elif defined(__APPLE__) || defined(__FreeBSD__)
291 struct kevent events[2];
294 m_poll_interest |= mode;
298 if (mode & PollEvent::READ) {
299 EV_SET(&events[count], m_sd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0,
this);
302 if (mode & PollEvent::WRITE) {
303 EV_SET(&events[count], m_sd, EVFILT_WRITE, EV_ADD | EV_ENABLE, 0, 0,
this);
308 if (kevent(m_reactor->kqd, events, count, 0, 0, 0) == -1) {
309 HT_DEBUGF(
"kevent(sd=%d) (mode=%x) : %s", m_sd, mode, strerror(errno));
317 struct kevent devents[2];
320 m_poll_interest &= ~mode;
324 if (mode & PollEvent::READ) {
325 EV_SET(&devents[count], m_sd, EVFILT_READ, EV_DELETE, 0, 0, 0);
329 if (mode & PollEvent::WRITE) {
330 EV_SET(&devents[count], m_sd, EVFILT_WRITE, EV_DELETE, 0, 0, 0);
334 if (kevent(m_reactor->kqd, devents, count, 0, 0, 0) == -1
335 && errno != ENOENT) {
336 HT_DEBUGF(
"kevent(sd=%d) (mode=%x) : %s", m_sd, mode, strerror(errno));
348 clog <<
"kevent: ident=" << hex << (long)event->ident;
350 switch (event->filter) {
352 clog <<
", EVFILT_READ, fflags=";
353 if (event->fflags & NOTE_LOWAT)
354 clog <<
"NOTE_LOWAT";
356 clog <<
event->fflags;
359 clog <<
", EVFILT_WRITE, fflags=";
360 if (event->fflags & NOTE_LOWAT)
361 clog <<
"NOTE_LOWAT";
363 clog <<
event->fflags;
366 clog <<
", EVFILT_AIO, fflags=" <<
event->fflags;
369 clog <<
", EVFILT_VNODE, fflags={";
370 if (event->fflags & NOTE_DELETE)
371 clog <<
" NOTE_DELETE";
372 if (event->fflags & NOTE_WRITE)
373 clog <<
" NOTE_WRITE";
374 if (event->fflags & NOTE_EXTEND)
375 clog <<
" NOTE_EXTEND";
376 if (event->fflags & NOTE_ATTRIB)
377 clog <<
" NOTE_ATTRIB";
378 if (event->fflags & NOTE_LINK)
379 clog <<
" NOTE_LINK";
380 if (event->fflags & NOTE_RENAME)
381 clog <<
" NOTE_RENAME";
382 if (event->fflags & NOTE_REVOKE)
383 clog <<
" NOTE_REVOKE";
387 clog <<
", EVFILT_VNODE, fflags={";
388 if (event->fflags & NOTE_EXIT)
389 clog <<
" NOTE_EXIT";
390 if (event->fflags & NOTE_FORK)
391 clog <<
" NOTE_FORK";
392 if (event->fflags & NOTE_EXEC)
393 clog <<
" NOTE_EXEC";
394 if (event->fflags & NOTE_TRACK)
395 clog <<
" NOTE_TRACK";
396 if (event->fflags & NOTE_TRACKERR)
397 clog <<
" NOTE_TRACKERR";
398 if (event->fflags & NOTE_CHILD)
399 clog <<
" NOTE_CHILD";
400 clog <<
" pid=" << (
event->flags & NOTE_PDATAMASK);
403 clog <<
", EVFILT_SIGNAL, fflags=" <<
event->fflags;
407 clog <<
", EVFILT_TIMER, fflags=" <<
event->fflags;
409 clog <<
", EVFILT_TIMER, fflags={";
410 if (event->fflags & NOTE_SECONDS)
411 clog <<
" NOTE_SECONDS";
412 if (event->fflags & NOTE_USECONDS)
413 clog <<
" NOTE_USECONDS";
414 if (event->fflags & NOTE_NSECONDS)
415 clog <<
" NOTE_NSECONDS";
416 if (event->fflags & NOTE_ABSOLUTE)
417 clog <<
" NOTE_ABSOLUTE";
423 if(event->flags != 0) {
425 if ((event->flags & EV_EOF) || (
event->flags & EV_ERROR)) {
427 if (event->flags & EV_EOF)
429 if (event->flags & EV_ERROR)
434 clog << hex <<
event->flags;
436 clog <<
", data=" << dec << (long)event->data << endl;
int start_polling(int mode=PollEvent::READ)
Start polling on the handler with the poll interest specified in mode.
#define HANDLE_POLL_INTERFACE_MODIFY
Declarations for ReactorRunner.
static bool ms_epollet
Use "edge triggered" epoll.
int remove_poll_interest(int mode)
Removes the poll interest specified in mode to the polling interface for this handler.
void display_event(struct pollfd *event)
Display polling event from poll() interface to stderr.
Logging routines and macros.
Compatibility Macros for C/C++.
Declarations for Reactor.
#define HT_DEBUGF(msg,...)
Writing can be performed without blocking.
#define HANDLE_POLL_INTERFACE_ADD
int add_poll_interest(int mode)
Adds the poll interest specified in mode to the polling interface for this handler.
Declarations for IOHandler.