/dev/poll support

This commit is contained in:
roberto@sirius
2010-04-01 10:31:04 +02:00
parent 3d098358da
commit c1956fc371
3 changed files with 73 additions and 0 deletions
+71
View File
@@ -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 ;
+1
View File
@@ -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
+1
View File
@@ -70,6 +70,7 @@
#include <sys/sendfile.h>
#include <sys/epoll.h>
#elif defined(__sun___)
#include <sys/devpoll.h>
#else
#include <sys/event.h>
#endif