From c1956fc3717212a6948ddf8cb6649f27fa116f1a Mon Sep 17 00:00:00 2001 From: "roberto@sirius" Date: Thu, 1 Apr 2010 10:31:04 +0200 Subject: [PATCH] /dev/poll support --- async.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ uwsgi.c | 1 + uwsgi.h | 1 + 3 files changed, 73 insertions(+) diff --git a/async.c b/async.c index 510fee8e..dd48d9ed 100644 --- a/async.c +++ b/async.c @@ -96,6 +96,77 @@ int async_del(int queuefd, int fd, int etype) { } #elif defined(__sun__) + +int async_queue_init(int serverfd) { + int dpfd ; + struct pollfd dpev; + + dpfd = open("/dev/poll", O_RDWR); + + if (dpfd < 0) { + perror("open()"); + return -1 ; + } + + dpev.fd = serverfd; + dpev.events = POLLIN ; + + if (write(dpfd, &dpev, sizeof(struct pollfd)) < 0) { + perror("write()"); + return -1; + } + + return dpfd; +} + +int async_wait(int queuefd, void *events, int nevents, int block, int timeout) { + + int ret ; + struct dvpoll dv ; + + if (timeout <= 0) { + timeout = block; + } + else { + timeout = timeout*1000; + } + + dv.dp_fds = (struct pollfd *) events; + dv.dp_nfds = nevents; + dv.dp_timeout = timeout; + + //fprintf(stderr,"waiting with timeout %d nevents %d\n", timeout, nevents); + ret = ioctl(queuefd, DP_POLL, &dv); + if (ret < 0) { + perror("ioctl()"); + } + return ret ; +} + +int async_add(int queuefd, int fd, int etype) { + struct pollfd pl; + + pl.fd = fd ; + pl.events = etype ; + + if (write(queuefd, &pl, sizeof(struct pollfd))) { + perror("write()"); + return -1; + } + + return 0; +} + +int async_mod(int queuefd, int fd, int etype) { + // using the same fd will overwrite existing rule + return async_add(queuefd, fd, etype); +} + +int async_del(int queuefd, int fd, int etype) { + // to remove an fd from /dev/poll you have to simply close it + return 0; +} + #else int async_queue_init(int serverfd) { int kfd ; diff --git a/uwsgi.c b/uwsgi.c index 176de2be..e1bb4d54 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -739,6 +739,7 @@ int main(int argc, char *argv[], char *envp[]) { #ifdef __linux__ uwsgi.async_events = malloc( sizeof(struct epoll_event) * uwsgi.async ) ; #elif defined(__sun__) + uwsgi.async_events = malloc( sizeof(struct pollfd) * uwsgi.async ) ; #else uwsgi.async_events = malloc( sizeof(struct kevent) * uwsgi.async ) ; #endif diff --git a/uwsgi.h b/uwsgi.h index c9107efa..f0e9b91e 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -70,6 +70,7 @@ #include #include #elif defined(__sun___) +#include #else #include #endif