From 3d156604076f9ea202abbb24ae46b7cc7b9698e8 Mon Sep 17 00:00:00 2001 From: Unbit Date: Tue, 3 Dec 2013 19:34:15 +0100 Subject: [PATCH] added a skel hook for waiting for 2 file descriptors --- core/init.c | 1 + core/reader.c | 33 +++++++++++++++++++++++++++++++++ uwsgi.h | 2 ++ 3 files changed, 36 insertions(+) diff --git a/core/init.c b/core/init.c index 466fd3c7..a81e9538 100644 --- a/core/init.c +++ b/core/init.c @@ -171,6 +171,7 @@ void uwsgi_init_default() { uwsgi.wait_read_hook = uwsgi_simple_wait_read_hook; uwsgi.wait_write_hook = uwsgi_simple_wait_write_hook; uwsgi.wait_milliseconds_hook = uwsgi_simple_wait_milliseconds_hook; + uwsgi.wait_read2_hook = uwsgi_simple_wait_read2_hook; uwsgi_websockets_init(); diff --git a/core/reader.c b/core/reader.c index 70441cf7..b994511a 100644 --- a/core/reader.c +++ b/core/reader.c @@ -24,6 +24,39 @@ int uwsgi_simple_wait_read_hook(int fd, int timeout) { return ret; } +int uwsgi_simple_wait_read2_hook(int fd0, int fd1, int timeout, int *fd) { + struct pollfd upoll[2]; + timeout = timeout * 1000; + + upoll[0].fd = fd0; + upoll[0].events = POLLIN; + upoll[0].revents = 0; + + upoll[0].fd = fd0; + upoll[0].events = POLLIN; + upoll[0].revents = 0; + + int ret = poll(upoll, 2, timeout); + + if (ret > 0) { + if (upoll[0].revents & POLLIN) { + *fd = fd0; + return 1; + } + if (upoll[1].revents & POLLIN) { + *fd = fd1; + return 1; + } + return -1; + } + if (ret < 0) { + uwsgi_error("uwsgi_simple_wait_read_hook2()/poll()"); + } + + return ret; +} + + /* seek()/rewind() language-independent implementations. */ diff --git a/uwsgi.h b/uwsgi.h index b29c3a34..fece647a 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2606,6 +2606,7 @@ struct uwsgi_server { int (*wait_write_hook) (int, int); int (*wait_read_hook) (int, int); int (*wait_milliseconds_hook) (int); + int (*wait_read2_hook) (int, int, int, int *); struct uwsgi_string_list *schemes; @@ -4195,6 +4196,7 @@ struct uwsgi_buffer *uwsgi_proto_base_add_header(struct wsgi_request *, char *, int uwsgi_simple_wait_write_hook(int, int); int uwsgi_simple_wait_read_hook(int, int); +int uwsgi_simple_wait_read2_hook(int, int, int, int *); int uwsgi_simple_wait_milliseconds_hook(int); int uwsgi_response_write_headers_do(struct wsgi_request *); char *uwsgi_request_body_read(struct wsgi_request *, ssize_t , ssize_t *);