ioevent for BSD ok

pull/5/head
yuqing 2015-09-13 20:49:09 +08:00
parent 07ffa9e6bd
commit e46333c00a
3 changed files with 27 additions and 9 deletions

View File

@ -1,10 +1,11 @@
Version 1.21 2015-09-08
Version 1.21 2015-09-13
* ini_file_reader support annotation function
* correct PTHREAD_MUTEX_ERRORCHECK define
* support 32 bit OS
* allow_ips support CIDR addresses such as 172.16.12.0/22
* add function get_first_local_ip
* ioevent for BSD ok
Version 1.20 2015-08-06
* add GEO function get_line_distance_km

View File

@ -47,6 +47,7 @@ int ioevent_init(IOEventPoller *ioevent, const int size,
ioevent->poll_fd = kqueue();
bytes = sizeof(struct kevent) * size;
ioevent->events = (struct kevent *)malloc(bytes);
ioevent->care_events = 0;
#elif IOEVENT_USE_PORT
ioevent->poll_fd = port_create();
bytes = sizeof(port_event_t) * size;
@ -92,6 +93,7 @@ int ioevent_attach(IOEventPoller *ioevent, const int fd, const int e,
if (e & IOEVENT_WRITE) {
EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_ADD | ioevent->extra_events, 0, 0, data);
}
ioevent->care_events = e;
return kevent(ioevent->poll_fd, ev, n, NULL, 0, NULL);
#elif IOEVENT_USE_PORT
return port_associate(ioevent->poll_fd, PORT_SOURCE_FD, fd, e, data);
@ -111,18 +113,23 @@ int ioevent_modify(IOEventPoller *ioevent, const int fd, const int e,
struct kevent ev[2];
int n = 0;
if (e & IOEVENT_READ) {
EV_SET(&ev[n++], fd, EVFILT_READ, EV_ADD | ioevent->extra_events, 0, 0, data);
if (!(ioevent->care_events & IOEVENT_READ)) {
EV_SET(&ev[n++], fd, EVFILT_READ, EV_ADD | ioevent->extra_events, 0, 0, data);
}
}
else {
EV_SET(&ev[n++], fd, EVFILT_READ, EV_DELETE, 0, 0, data);
else if ((ioevent->care_events & IOEVENT_READ)) {
EV_SET(&ev[n++], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
}
if (e & IOEVENT_WRITE) {
EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_ADD | ioevent->extra_events, 0, 0, data);
if (!(ioevent->care_events & IOEVENT_WRITE)) {
EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_ADD | ioevent->extra_events, 0, 0, data);
}
}
else {
EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_DELETE, 0, 0, data);
else if ((ioevent->care_events & IOEVENT_WRITE)) {
EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
}
ioevent->care_events = e;
return kevent(ioevent->poll_fd, ev, n, NULL, 0, NULL);
#elif IOEVENT_USE_PORT
return port_associate(ioevent->poll_fd, PORT_SOURCE_FD, fd, e, data);
@ -133,10 +140,19 @@ int ioevent_detach(IOEventPoller *ioevent, const int fd)
{
#if IOEVENT_USE_EPOLL
return epoll_ctl(ioevent->poll_fd, EPOLL_CTL_DEL, fd, NULL);
#elif IOEVENT_USE_KQUEUE
struct kevent ev[2];
int n = 0;
if ((ioevent->care_events & IOEVENT_READ)) {
EV_SET(&ev[n++], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
}
if ((ioevent->care_events & IOEVENT_WRITE)) {
EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
}
ioevent->care_events = 0;
return kevent(ioevent->poll_fd, ev, n, NULL, 0, NULL);
#elif IOEVENT_USE_PORT
return port_dissociate(ioevent->poll_fd, PORT_SOURCE_FD, fd);
#else
return 0;
#endif
}

View File

@ -64,6 +64,7 @@ typedef struct ioevent_puller {
#elif IOEVENT_USE_KQUEUE
struct kevent *events;
struct timespec timeout;
int care_events;
#elif IOEVENT_USE_PORT
port_event_t *events;
timespec_t timeout;