projects
/
IOMultiplexer.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[IOMultiplexer] Added asynchronous DNS Lookups
[IOMultiplexer.git]
/
src
/
IOEngine_epoll.c
diff --git
a/src/IOEngine_epoll.c
b/src/IOEngine_epoll.c
index d1c139f6970f734a4fdb65ef2b9d5dde12e50e30..e115c003b155da6206d8aa4dbdbc287d654a8754 100644
(file)
--- a/
src/IOEngine_epoll.c
+++ b/
src/IOEngine_epoll.c
@@
-33,40
+33,44
@@
static int engine_epoll_init() {
return 1;
}
return 1;
}
-static void engine_epoll_add(struct IO
Descriptor *iof
d) {
- if(io
fd->type == IOTYPE_TIMER
) return;
+static void engine_epoll_add(struct IO
LowlevelDescriptor *iol
d) {
+ if(io
ld->fd != -1
) return;
//add descriptor to the epoll queue
struct epoll_event evt;
int res;
//add descriptor to the epoll queue
struct epoll_event evt;
int res;
- evt.events = EPOLLHUP |
EPOLLIN | (iohandler_wants_writes(iofd
) ? EPOLLOUT : 0);
- evt.data.ptr = io
f
d;
- res = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, io
f
d->fd, &evt);
+ evt.events = EPOLLHUP |
((iold->flags & IOFLAGS_WANT_READ) ? EPOLLIN : 0) | ((iold->flags & IOFLAGS_WANT_WRITE
) ? EPOLLOUT : 0);
+ evt.data.ptr = io
l
d;
+ res = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, io
l
d->fd, &evt);
if(res < 0) {
if(res < 0) {
- iohandler_log(IOLOG_ERROR, "could not add IO
Descriptor %d to epoll queue. (returned: %d)", iof
d->fd, res);
+ iohandler_log(IOLOG_ERROR, "could not add IO
LowlevelDescriptor %d to epoll queue. (returned: %d)", iol
d->fd, res);
}
}
}
}
-static void engine_epoll_remove(struct IO
Descriptor *iof
d) {
- if(io
fd->type == IOTYPE_TIMER
) return;
+static void engine_epoll_remove(struct IO
LowlevelDescriptor *iol
d) {
+ if(io
ld->fd != -1
) return;
struct epoll_event evt;
struct epoll_event evt;
- epoll_ctl(epoll_fd, EPOLL_CTL_DEL, io
f
d->fd, &evt);
+ epoll_ctl(epoll_fd, EPOLL_CTL_DEL, io
l
d->fd, &evt);
}
}
-static void engine_epoll_update(struct IODescriptor *iofd) {
- if(iofd->type == IOTYPE_TIMER) return;
- if(iofd->state == IO_CLOSED) {
- engine_epoll_remove(iofd);
- return;
+static void engine_epoll_update(struct IOLowlevelDescriptor *iold) {
+ if(iold->fd != -1) return;
+ struct IODescriptor *iofd;
+ if((iofd = IOLOWLEVEL_GET_IOFD(iold))) {
+ if(iofd->state == IO_CLOSED) {
+ engine_epoll_remove(iold);
+ return;
+ }
}
}
+
struct epoll_event evt;
int res;
struct epoll_event evt;
int res;
- evt.events = EPOLLHUP |
EPOLLIN | (iohandler_wants_writes(iofd
) ? EPOLLOUT : 0);
- evt.data.ptr = io
f
d;
- res = epoll_ctl(epoll_fd, EPOLL_CTL_MOD, io
f
d->fd, &evt);
+ evt.events = EPOLLHUP |
((iold->flags & IOFLAGS_WANT_READ) ? EPOLLIN : 0) | ((iold->flags & IOFLAGS_WANT_WRITE
) ? EPOLLOUT : 0);
+ evt.data.ptr = io
l
d;
+ res = epoll_ctl(epoll_fd, EPOLL_CTL_MOD, io
l
d->fd, &evt);
if(res < 0) {
if(res < 0) {
- iohandler_log(IOLOG_ERROR, "could not update IO
Descriptor %d in epoll queue. (returned: %d)", iof
d->fd, res);
+ iohandler_log(IOLOG_ERROR, "could not update IO
LowlevelDescriptor %d in epoll queue. (returned: %d)", iol
d->fd, res);
}
}
}
}
@@
-76,6
+80,7
@@
static void engine_epoll_loop(struct timeval *timeout) {
int msec;
int events;
int epoll_result;
int msec;
int events;
int epoll_result;
+ struct IOLowlevelDescriptor *iold;
gettimeofday(&now, NULL);
gettimeofday(&now, NULL);
@@
-117,7
+122,11
@@
static void engine_epoll_loop(struct timeval *timeout) {
int i;
for(i = 0; i < epoll_result; i++) {
events = evts[i].events;
int i;
for(i = 0; i < epoll_result; i++) {
events = evts[i].events;
- iohandler_events(evts[i].data.ptr, (events & (EPOLLIN | EPOLLHUP)), (events & EPOLLOUT));
+ iold = evts[i].data.ptr;
+ if(iold->flags & IOFLAGS_HAVE_IOFD)
+ iohandler_events(iold->data.iofd, (events & (EPOLLIN | EPOLLHUP)), (events & EPOLLOUT));
+ else
+ iold->data.callback(iold, (events & (EPOLLIN | EPOLLHUP)), (events & EPOLLOUT));
}
}
}
}