Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'new-events' into dev

  • Loading branch information...
commit 9a8b3492f666798f82b41e217e0db38eb21bad5f 2 parents 3976ff1 + 2a60fad
@alobbs alobbs authored
Showing with 788 additions and 829 deletions.
  1. +2 −0  cherokee/Makefile.am
  2. +2 −23 cherokee/bind.c
  3. +58 −0 cherokee/connection-poll.c
  4. +47 −0 cherokee/connection-poll.h
  5. +6 −8 cherokee/connection-protected.h
  6. +85 −48 cherokee/connection.c
  7. +1 −1  cherokee/connection_info.c
  8. +3 −3 cherokee/downloader_async.c
  9. +0 −4 cherokee/error_list.py
  10. +45 −30 cherokee/fdpoll-epoll.c
  11. +74 −37 cherokee/fdpoll-kqueue.c
  12. +58 −28 cherokee/fdpoll-poll.c
  13. +55 −30 cherokee/fdpoll-port.c
  14. +18 −16 cherokee/fdpoll-select.c
  15. +21 −18 cherokee/fdpoll-win32.c
  16. +5 −3 cherokee/fdpoll.h
  17. +9 −20 cherokee/handler_cgi.c
  18. +10 −19 cherokee/handler_fcgi.c
  19. +25 −60 cherokee/handler_proxy.c
  20. +8 −21 cherokee/handler_scgi.c
  21. +8 −21 cherokee/handler_uwsgi.c
  22. +51 −35 cherokee/post.c
  23. +24 −25 cherokee/post.h
  24. +8 −4 cherokee/server.c
  25. +20 −46 cherokee/socket.c
  26. +8 −10 cherokee/socket.h
  27. +2 −8 cherokee/source.c
  28. +2 −6 cherokee/source_interpreter.c
  29. +132 −299 cherokee/thread.c
  30. +1 −6 cherokee/thread.h
View
2  cherokee/Makefile.am
@@ -1577,6 +1577,8 @@ $(common_rrd_tools) \
\
connection.h \
connection-protected.h \
+connection-poll.h \
+connection-poll.c \
connection.c \
handler.h \
handler.c \
View
25 cherokee/bind.c
@@ -171,33 +171,12 @@ set_socket_opts (int socket)
if (ret != ret_ok)
return ret;
- /* TCP_MAXSEG:
- * The maximum size of a TCP segment is based on the network MTU for des-
- * tinations on local networks or on a default MTU of 576 bytes for desti-
- * nations on nonlocal networks. The default behavior can be altered by
- * setting the TCP_MAXSEG option to an integer value from 1 to 65,535.
- * However, TCP will not use a maximum segment size smaller than 32 or
- * larger than the local network MTU. Setting the TCP_MAXSEG option to a
- * value of zero results in default behavior. The TCP_MAXSEG option can
- * only be set prior to calling listen or connect on the socket. For pas-
- * sive connections, the TCP_MAXSEG option value is inherited from the
- * listening socket. This option takes an int value, with a range of 0 to
- * 65535.
- */
-#ifdef TCP_MAXSEG
- on = 64000;
- setsockopt (socket, SOL_SOCKET, TCP_MAXSEG, &on, sizeof(on));
-
- /* Do no check the returned value */
-#endif
-
/* TCP_DEFER_ACCEPT:
* Allows a listener to be awakened only when data arrives on the socket.
* Takes an integer value (seconds), this can bound the maximum number of
- * attempts TCP will make to complete the connection. This option should
- * not be used in code intended to be portable.
+ * attempts TCP will make to complete the connection.
*
- * Give clients 5s to send first data packet
+ * Gives clients 5secs to send the first data packet
*/
#ifdef TCP_DEFER_ACCEPT
on = 5;
View
58 cherokee/connection-poll.c
@@ -0,0 +1,58 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* Cherokee
+ *
+ * Authors:
+ * Alvaro Lopez Ortega <alvaro@alobbs.com>
+ *
+ * Copyright (C) 2001-2011 Alvaro Lopez Ortega
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include "common-internal.h"
+#include "connection-poll.h"
+
+ret_t
+cherokee_connection_poll_init (cherokee_connection_pool_t *conn_poll)
+{
+ conn_poll->fd = -1;
+ conn_poll->mode = poll_mode_nothing;
+
+ return ret_ok;
+}
+
+ret_t
+cherokee_connection_poll_mrproper (cherokee_connection_pool_t *conn_poll)
+{
+ UNUSED (conn_poll);
+ return ret_ok;
+}
+
+ret_t
+cherokee_connection_poll_clean (cherokee_connection_pool_t *conn_poll)
+{
+ conn_poll->fd = -1;
+ conn_poll->mode = poll_mode_nothing;
+
+ return ret_ok;
+}
+
+int
+cherokee_connection_poll_is_set (cherokee_connection_pool_t *conn_poll)
+{
+ return ((conn_poll->fd != -1) ||
+ (conn_poll->mode != poll_mode_nothing));
+}
View
47 cherokee/connection-poll.h
@@ -0,0 +1,47 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* Cherokee
+ *
+ * Authors:
+ * Alvaro Lopez Ortega <alvaro@alobbs.com>
+ *
+ * Copyright (C) 2001-2011 Alvaro Lopez Ortega
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#if !defined (CHEROKEE_INSIDE_CHEROKEE_H) && !defined (CHEROKEE_COMPILATION)
+# error "Only <cherokee/cherokee.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef CHEROKEE_CONNECTION_POLL_H
+#define CHEROKEE_CONNECTION_POLL_H
+
+#include "common.h"
+#include "fdpoll.h"
+
+
+typedef struct {
+ cherokee_poll_mode_t mode;
+ int fd;
+} cherokee_connection_pool_t;
+
+
+ret_t cherokee_connection_poll_init (cherokee_connection_pool_t *conn_poll);
+ret_t cherokee_connection_poll_clean (cherokee_connection_pool_t *conn_poll);
+ret_t cherokee_connection_poll_mrproper (cherokee_connection_pool_t *conn_poll);
+int cherokee_connection_poll_is_set (cherokee_connection_pool_t *conn_poll);
+
+#endif /* CHEROKEE_CONNECTION_POLL_H */
View
14 cherokee/connection-protected.h
@@ -68,6 +68,7 @@
#include "bind.h"
#include "bogotime.h"
#include "config_entry.h"
+#include "connection-poll.h"
typedef enum {
phase_nothing,
@@ -89,10 +90,9 @@ typedef enum {
#define conn_op_root_index (1 << 1)
#define conn_op_tcp_cork (1 << 2)
#define conn_op_document_root (1 << 3)
-#define conn_op_was_polling (1 << 4)
-#define conn_op_cant_encoder (1 << 5)
-#define conn_op_got_eof (1 << 6)
-#define conn_op_chunked_formatted (1 << 7)
+#define conn_op_cant_encoder (1 << 4)
+#define conn_op_got_eof (1 << 5)
+#define conn_op_chunked_formatted (1 << 6)
typedef cuint_t cherokee_connection_options_t;
@@ -192,9 +192,7 @@ struct cherokee_connection {
/* Polling
*/
- int polling_fd;
- cherokee_socket_status_t polling_mode;
- cherokee_boolean_t polling_multiple;
+ cherokee_connection_pool_t polling_aim;
off_t range_start;
off_t range_end;
@@ -254,7 +252,7 @@ struct cherokee_connection {
*/
ret_t cherokee_connection_new (cherokee_connection_t **conn);
ret_t cherokee_connection_free (cherokee_connection_t *conn);
-ret_t cherokee_connection_clean (cherokee_connection_t *conn);
+ret_t cherokee_connection_clean (cherokee_connection_t *conn, cherokee_boolean_t reuse);
ret_t cherokee_connection_clean_close (cherokee_connection_t *conn);
/* Close
View
133 cherokee/connection.c
@@ -120,9 +120,6 @@ cherokee_connection_new (cherokee_connection_t **conn)
n->timeout = -1;
n->timeout_lapse = -1;
n->timeout_header = NULL;
- n->polling_fd = -1;
- n->polling_multiple = false;
- n->polling_mode = FDPOLL_MODE_NONE;
n->expiration = cherokee_expiration_none;
n->expiration_time = 0;
n->expiration_prop = cherokee_expiration_prop_none;
@@ -158,7 +155,8 @@ cherokee_connection_new (cherokee_connection_t **conn)
cherokee_socket_init (&n->socket);
cherokee_header_init (&n->header, header_type_request);
- cherokee_post_init (&n->post);
+ cherokee_post_init (&n->post, n);
+ cherokee_connection_poll_init (&n->polling_aim);
memset (n->regex_ovector, 0, OVECTOR_LEN * sizeof(int));
n->regex_ovecsize = 0;
@@ -232,11 +230,11 @@ cherokee_connection_free (cherokee_connection_t *conn)
conn->arguments = NULL;
}
- if (conn->polling_fd != -1) {
- cherokee_fd_close (conn->polling_fd);
- conn->polling_fd = -1;
- conn->polling_mode = FDPOLL_MODE_NONE;
- }
+
+ if (conn->polling_aim.fd != -1) {
+ cherokee_fd_close (conn->polling_aim.fd);
+ }
+ cherokee_connection_poll_mrproper (&conn->polling_aim);
free (conn);
return ret_ok;
@@ -244,7 +242,8 @@ cherokee_connection_free (cherokee_connection_t *conn)
ret_t
-cherokee_connection_clean (cherokee_connection_t *conn)
+cherokee_connection_clean (cherokee_connection_t *conn,
+ cherokee_boolean_t reuse)
{
size_t crlf_len;
uint32_t header_len;
@@ -289,10 +288,10 @@ cherokee_connection_clean (cherokee_connection_t *conn)
conn->encoder_new_func = NULL;
conn->encoder_props = NULL;
- if (conn->polling_fd != -1) {
- cherokee_fd_close (conn->polling_fd);
- conn->polling_fd = -1;
+ if (conn->polling_aim.fd != -1) {
+ cherokee_fd_close (conn->polling_aim.fd);
}
+ cherokee_connection_poll_clean (&conn->polling_aim);
if (conn->validator != NULL) {
cherokee_validator_free (conn->validator);
@@ -315,8 +314,6 @@ cherokee_connection_clean (cherokee_connection_t *conn)
conn->rx_partial = 0;
conn->tx_partial = 0;
conn->traffic_next = 0;
- conn->polling_multiple = false;
- conn->polling_mode = FDPOLL_MODE_NONE;
conn->expiration = cherokee_expiration_none;
conn->expiration_time = 0;
conn->expiration_prop = cherokee_expiration_prop_none;
@@ -333,6 +330,8 @@ cherokee_connection_clean (cherokee_connection_t *conn)
memset (conn->regex_host_ovector, 0, OVECTOR_LEN * sizeof(int));
conn->regex_host_ovecsize = 0;
+ cherokee_connection_poll_clean (&conn->polling_aim);
+
cherokee_post_clean (&conn->post);
cherokee_buffer_mrproper (&conn->encoder_buffer);
@@ -373,27 +372,24 @@ cherokee_connection_clean (cherokee_connection_t *conn)
cherokee_buffer_clean (&conn->buffer);
cherokee_buffer_clean (&conn->header_buffer);
- /* Skip trailing CRLF (which may be sent by some HTTP clients)
- * only if the number of CRLFs is within the predefine count
- * limit otherwise ignore trailing CRLFs so that they will be
- * handled in next request. This may avoid a subsequent real
- * move_to_begin of the contents left in the buffer.
- */
- crlf_len = cherokee_buffer_cnt_spn (&conn->incoming_header, header_len, CRLF);
- header_len += (crlf_len <= MAX_HEADER_CRLF) ? crlf_len : 0;
+ if (reuse) {
+ /* Skip trailing CRLF (which may be sent by some HTTP clients)
+ * only if the number of CRLFs is within the predefine count
+ * limit otherwise ignore trailing CRLFs so that they will be
+ * handled in next request. This may avoid a subsequent real
+ * move_to_begin of the contents left in the buffer.
+ */
+ crlf_len = cherokee_buffer_cnt_spn (&conn->incoming_header, header_len, CRLF);
+ header_len += (crlf_len <= MAX_HEADER_CRLF) ? crlf_len : 0;
- cherokee_buffer_move_to_begin (&conn->incoming_header, header_len);
+ cherokee_buffer_move_to_begin (&conn->incoming_header, header_len);
- /* If the connection has incoming headers to be processed,
- * then increment the pending counter from the thread
- */
- if (! cherokee_buffer_is_empty (&conn->incoming_header)) {
- CONN_THREAD(conn)->pending_conns_num++;
+ TRACE (ENTRIES, "conn %p, %s headers\n", conn,
+ !cherokee_buffer_is_empty (&conn->incoming_header) ? "has" : "doesn't have");
+ } else {
+ cherokee_buffer_clean (&conn->incoming_header);
}
- TRACE (ENTRIES, "conn %p, has headers %d\n", conn,
- !cherokee_buffer_is_empty (&conn->incoming_header));
-
return ret_ok;
}
@@ -413,7 +409,7 @@ cherokee_connection_clean_close (cherokee_connection_t *conn)
/* Clean the connection object
*/
- cherokee_connection_clean (conn);
+ cherokee_connection_clean (conn, false);
return ret_ok;
}
@@ -1057,8 +1053,12 @@ cherokee_connection_send_header_and_mmaped (cherokee_connection_t *conn)
if (unlikely (ret != ret_ok) ) {
switch (ret) {
case ret_eof:
+ return ret_eof;
+
case ret_eagain:
- return ret;
+ conn->polling_aim.fd = conn->socket.socket;
+ conn->polling_aim.mode = poll_mode_write;
+ return ret_eagain;
case ret_error:
conn->keepalive = 0;
@@ -1095,8 +1095,12 @@ cherokee_connection_send_header_and_mmaped (cherokee_connection_t *conn)
switch (ret) {
case ret_eof:
+ return ret_eof;
+
case ret_eagain:
- return ret;
+ conn->polling_aim.fd = conn->socket.socket;
+ conn->polling_aim.mode = poll_mode_write;
+ return ret_eagain;
case ret_error:
conn->keepalive = 0;
@@ -1188,15 +1192,15 @@ cherokee_connection_recv (cherokee_connection_t *conn,
return ret;
case ret_eagain:
- if (cherokee_socket_pending_read (&conn->socket)) {
- CONN_THREAD(conn)->pending_read_num += 1;
- }
-
if (cnt_read > 0) {
cherokee_connection_rx_add (conn, cnt_read);
*len = cnt_read;
return ret_ok;
}
+
+ conn->polling_aim.fd = conn->socket.socket;
+ conn->polling_aim.mode = poll_mode_read;
+
return ret_eagain;
default:
@@ -1254,7 +1258,18 @@ cherokee_connection_send_header (cherokee_connection_t *conn)
/* Send the buffer content
*/
ret = cherokee_socket_bufwrite (&conn->socket, &conn->buffer, &sent);
- if (unlikely(ret != ret_ok)) return ret;
+ switch (ret) {
+ case ret_ok:
+ break;
+
+ case ret_eagain:
+ conn->polling_aim.fd = conn->socket.socket;
+ conn->polling_aim.mode = poll_mode_write;
+ return ret_eagain;
+
+ default:
+ return ret;
+ }
/* Add to the connection traffic counter
*/
@@ -1340,8 +1355,12 @@ cherokee_connection_send (cherokee_connection_t *conn)
break;
case ret_eof:
+ return ret_eof;
+
case ret_eagain:
- return ret;
+ conn->polling_aim.fd = conn->socket.socket;
+ conn->polling_aim.mode = poll_mode_write;
+ return ret_eagain;
case ret_error:
conn->keepalive = 0;
@@ -1379,8 +1398,18 @@ cherokee_connection_send (cherokee_connection_t *conn)
}
ret = cherokee_socket_write (&conn->socket, conn->buffer.buf, to_send, &sent);
- if (unlikely(ret != ret_ok))
+ switch (ret) {
+ case ret_ok:
+ break;
+
+ case ret_eagain:
+ conn->polling_aim.fd = conn->socket.socket;
+ conn->polling_aim.mode = poll_mode_write;
+ return ret_eagain;
+
+ default:
return ret;
+ }
/* Drop out the sent info
*/
@@ -1523,12 +1552,17 @@ cherokee_connection_linger_read (cherokee_connection_t *conn)
cherokee_thread_t *thread = CONN_THREAD(conn);
cherokee_buffer_t *tmp1 = THREAD_TMP_BUF1(thread);
- TRACE(ENTRIES",linger", "Linger read, socket status %d\n", conn->socket.status);
+ TRACE(ENTRIES",linger", "Linger read, socket %s closed\n", conn->socket.closed ? "is" : "isn't");
while (true) {
/* Read from the socket to nowhere
*/
- ret = cherokee_socket_read (&conn->socket, tmp1->buf, tmp1->size, &cnt_read);
+ ret = cherokee_socket_read (&conn->socket, tmp1->buf, tmp1->size - 1, &cnt_read);
+
+ if (cnt_read > 0) {
+ cherokee_buffer_clean (tmp1);
+ }
+
switch (ret) {
case ret_eof:
TRACE (ENTRIES",linger", "%s\n", "EOF");
@@ -1538,12 +1572,17 @@ cherokee_connection_linger_read (cherokee_connection_t *conn)
return ret_error;
case ret_eagain:
TRACE (ENTRIES",linger", "read %u, eagain\n", cnt_read);
+
+ conn->polling_aim.fd = conn->socket.socket;
+ conn->polling_aim.mode = poll_mode_read;
return ret_eagain;
case ret_ok:
TRACE (ENTRIES",linger", "%u bytes tossed away\n", cnt_read);
+
retries--;
- if (cnt_read == tmp1->size && retries > 0)
+ if ((cnt_read >= tmp1->size - 2) && (retries > 0))
continue;
+
return ret_eof;
default:
RET_UNKNOWN(ret);
@@ -2176,7 +2215,7 @@ cherokee_connection_get_request (cherokee_connection_t *conn)
*/
if (read_post)
{
- ret = cherokee_post_read_header (&conn->post, conn);
+ ret = cherokee_post_read_header (&conn->post);
if (unlikely (ret != ret_ok)) {
return ret;
}
@@ -2858,8 +2897,6 @@ cherokee_connection_print (cherokee_connection_t *conn)
print_add (" tcp_cork");
if (conn->options & conn_op_document_root)
print_add (" document_root");
- if (conn->options & conn_op_was_polling)
- print_add (" was_polling");
if (conn->options & conn_op_cant_encoder)
print_add (" cant_encoder");
if (conn->options & conn_op_got_eof)
View
2  cherokee/connection_info.c
@@ -186,7 +186,7 @@ cherokee_connection_info_list_thread (cherokee_list_t *list,
/* Does it has active connections?
*/
- if (thread->active_list_num <= 0)
+ if (cherokee_list_empty (&thread->active_list))
return ret_not_found;
/* If it tries to adquire the thread ownership of the thread
View
6 cherokee/downloader_async.c
@@ -93,7 +93,7 @@ cherokee_downloader_async_connect (cherokee_downloader_async_t *adownloader)
ret = cherokee_fd_set_nonblocking (down->socket.socket, true);
if (ret != ret_ok) return ret;
- ret = cherokee_fdpoll_add (fdpoll, down->socket.socket, FDPOLL_MODE_WRITE);
+ ret = cherokee_fdpoll_add (fdpoll, down->socket.socket, poll_mode_write);
if (ret != ret_ok) return ret;
adownloader->fd_added = down->socket.socket;
@@ -123,9 +123,9 @@ cherokee_downloader_async_step (cherokee_downloader_async_t *adownloader)
/* Check whether we are reading or writting
*/
if (down->phase <= downloader_phase_send_post)
- rw = FDPOLL_MODE_WRITE;
+ rw = poll_mode_write;
else
- rw = FDPOLL_MODE_READ;
+ rw = poll_mode_read;
TRACE(ENTRIES, "rw = %d\n", rw);
View
4 cherokee/error_list.py
@@ -904,10 +904,6 @@
# cherokee/thread.c
#
-e('THREAD_RM_FD_POLL',
- title = "Could not remove fd(%d) from fdpoll",
- desc = CODING_BUG)
-
e('THREAD_HANDLER_RET',
title = "Unknown ret %d from handler %s",
desc = CODING_BUG)
View
75 cherokee/fdpoll-epoll.c
@@ -80,7 +80,7 @@ _free (cherokee_fdpoll_epoll_t *fdp)
static ret_t
-_add (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
+_add (cherokee_fdpoll_epoll_t *fdp, int fd, int mode_rw)
{
struct epoll_event ev;
@@ -94,16 +94,20 @@ _add (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
/* Add the new descriptor
*/
ev.data.u64 = 0;
- ev.data.fd = fd;
- switch (rw) {
- case FDPOLL_MODE_READ:
- ev.events = EPOLLIN | EPOLLERR | EPOLLHUP;
- break;
- case FDPOLL_MODE_WRITE:
- ev.events = EPOLLOUT | EPOLLERR | EPOLLHUP;
- break;
- default:
- ev.events = 0;
+ ev.data.fd = fd;
+ ev.events = 0;
+
+ /* Set mode
+ */
+ if (mode_rw & poll_mode_read) {
+ ev.events |= (EPOLLIN | EPOLLERR | EPOLLHUP);
+ }
+
+ if (mode_rw & poll_mode_write) {
+ ev.events |= (EPOLLOUT | EPOLLERR | EPOLLHUP);
+ }
+
+ if (unlikely (ev.events == 0)) {
SHOULDNT_HAPPEN;
return ret_error;
}
@@ -147,7 +151,7 @@ _del (cherokee_fdpoll_epoll_t *fdp, int fd)
static int
-_check (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
+_check (cherokee_fdpoll_epoll_t *fdp, int fd, int rw_mode)
{
int fdidx;
uint32_t events;
@@ -181,14 +185,19 @@ _check (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
*/
events = fdp->ep_events[fdidx].events;
- switch (rw) {
- case FDPOLL_MODE_READ:
- return events & (EPOLLIN | EPOLLERR | EPOLLHUP);
- case FDPOLL_MODE_WRITE:
- return events & (EPOLLOUT | EPOLLERR | EPOLLHUP);
- default:
- return -1;
+ if ((rw_mode & poll_mode_read) && (events & EPOLLIN)) {
+ return 1;
+ }
+
+ if ((rw_mode & poll_mode_write) && (events & EPOLLOUT)) {
+ return 1;
}
+
+ if (events & (EPOLLERR | EPOLLHUP)) {
+ return 1;
+ }
+
+ return -1;
}
@@ -207,30 +216,36 @@ _reset (cherokee_fdpoll_epoll_t *fdp, int fd)
static ret_t
-_set_mode (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
+_set_mode (cherokee_fdpoll_epoll_t *fdp, int fd, int rw_mode)
{
struct epoll_event ev;
ev.data.u64 = 0;
ev.data.fd = fd;
+ ev.events = 0;
- switch (rw) {
- case FDPOLL_MODE_READ:
- ev.events = EPOLLIN;
- break;
- case FDPOLL_MODE_WRITE:
- ev.events = EPOLLOUT;
- break;
- default:
- ev.events = 0;
+ /* Set mode
+ */
+ if (rw_mode & poll_mode_read) {
+ ev.events |= (EPOLLIN | EPOLLERR | EPOLLHUP);
+ }
+
+ if (rw_mode & poll_mode_write) {
+ ev.events |= (EPOLLOUT | EPOLLERR | EPOLLHUP);
+ }
+
+ if (unlikely (ev.events == 0)) {
return ret_error;
}
- if (epoll_ctl(fdp->ep_fd, EPOLL_CTL_MOD, fd, &ev) < 0) {
+ /* Apply it
+ */
+ if (epoll_ctl (fdp->ep_fd, EPOLL_CTL_MOD, fd, &ev) < 0) {
LOG_ERRNO (errno, cherokee_err_error,
CHEROKEE_ERROR_FDPOLL_EPOLL_CTL_MOD, fdp->ep_fd, fd);
return ret_error;
}
+
return ret_ok;
}
View
111 cherokee/fdpoll-kqueue.c
@@ -91,11 +91,15 @@ _free (cherokee_fdpoll_kqueue_t *fdp)
static ret_t
-_add_change(cherokee_fdpoll_kqueue_t *fdp, int fd, int rw, int change )
+_add_change (cherokee_fdpoll_kqueue_t *fdp, int fd, int mode, int change)
{
int index;
struct kevent *event;
+ /* The 'mode' variable should contain a single mode here. This
+ * function does not support multiple modes.
+ */
+
index = fdp->nchanges;
if (unlikely (index >= FDPOLL(fdp)->nfiles)) {
PRINT_ERROR_S("kqueue_add: fdpoll is full !\n");
@@ -104,21 +108,23 @@ _add_change(cherokee_fdpoll_kqueue_t *fdp, int fd, int rw, int change )
event = &fdp->changelist[index];
event->ident = fd;
- switch (rw) {
- case FDPOLL_MODE_READ:
+
+ switch (mode) {
+ case poll_mode_read:
event->filter = EVFILT_READ;
break;
- case FDPOLL_MODE_WRITE:
+ case poll_mode_write:
event->filter = EVFILT_WRITE;
break;
default:
+ event->filter = 0;
SHOULDNT_HAPPEN;
- }
+ }
event->flags = change;
event->fflags = 0;
- fdp->fdinterest[fd] = rw;
+ fdp->fdinterest[fd] = mode;
fdp->nchanges++;
return ret_ok;
@@ -126,30 +132,55 @@ _add_change(cherokee_fdpoll_kqueue_t *fdp, int fd, int rw, int change )
static ret_t
-_add (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw)
+_add (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw_mode)
{
- int re;
+ ret_t ret = ret_not_found;
+
+ if (rw_mode & poll_mode_read) {
+ ret = _add_change (fdp, fd, poll_mode_read, EV_ADD);
+ if (ret != ret_ok)
+ return ret;
+ }
- re = _add_change (fdp, fd, rw, EV_ADD);
- if (re == ret_ok) {
+ if (rw_mode & poll_mode_write) {
+ ret = _add_change (fdp, fd, poll_mode_write, EV_ADD);
+ if (ret != ret_ok)
+ return ret;
+ }
+
+ if (ret == ret_ok) {
FDPOLL(fdp)->npollfds++;
}
- return re;
+ return ret;
}
static ret_t
_del (cherokee_fdpoll_kqueue_t *fdp, int fd)
{
- int re;
+ ret_t ret = ret_not_found;
+ int interest = fdp->fdinterest[fd];
+ cherokee_boolean_t error = false;
+
+ if (interest & poll_mode_read) {
+ ret = _add_change (fdp, fd, poll_mode_read, EV_DELETE);
+ if (ret != ret_ok)
+ error = true;
+ }
- re = _add_change (fdp, fd, fdp->fdinterest[fd], EV_DELETE);
- if (re == ret_ok) {
+ if (interest & poll_mode_write) {
+ ret = _add_change (fdp, fd, poll_mode_write, EV_DELETE);
+ if (ret != ret_ok)
+ error |= true;
+ }
+
+ if ((ret == ret_ok) && (! error)) {
FDPOLL(fdp)->npollfds--;
}
- return re;
+ fdp->fdinterest[fd] = 0;
+ return ret;
}
@@ -183,7 +214,7 @@ _watch (cherokee_fdpoll_kqueue_t *fdp, int timeout_msecs)
LOG_ERRNO (errno, cherokee_err_error, CHEROKEE_ERROR_FDPOLL_KQUEUE);
return 0;
- } else if (n_events > 0) {
+ } else if (n_events >= 0) {
memset (fdp->fdevents, 0, FDPOLL(fdp)->system_nfiles * sizeof(int));
for (i = 0; i < n_events; ++i) {
@@ -207,7 +238,7 @@ _watch (cherokee_fdpoll_kqueue_t *fdp, int timeout_msecs)
}
static int
-_check (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw)
+_check (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw_mode)
{
uint32_t events;
@@ -223,15 +254,16 @@ _check (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw)
return 1;
}
- switch (rw) {
- case FDPOLL_MODE_READ:
- events &= KQUEUE_READ_EVENT;
- break;
- case FDPOLL_MODE_WRITE:
- events &= KQUEUE_WRITE_EVENT;
- break;
- default:
- SHOULDNT_HAPPEN;
+ if ((rw_mode & poll_mode_read) &&
+ (events & KQUEUE_READ_EVENT))
+ {
+ return 1;
+ }
+
+ if ((rw_mode & poll_mode_write) &&
+ (events & KQUEUE_WRITE_EVENT))
+ {
+ return 1;
}
return events;
@@ -249,24 +281,29 @@ _reset (cherokee_fdpoll_kqueue_t *fdp, int fd)
static ret_t
-_set_mode (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw)
+_set_mode (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw_mode)
{
- /* If transitioning from r -> w or from w -> r
- * disable any active event on the fd as we are
- * no longer interested on it.
+ int prev_interest = fdp->fdinterest[fd];
+
+ /* If transitioning from R->W or from W->R disable any active
+ * event on the fd as we are no longer interested on it.
*/
- if ((rw == FDPOLL_MODE_WRITE) &&
- (fdp->fdinterest[fd] == FDPOLL_MODE_READ))
+
+ /* No longer reading */
+ if ((! (rw_mode & poll_mode_read)) &&
+ (prev_interest & poll_mode_read))
{
- _add_change (fdp, fd, FDPOLL_MODE_READ, EV_DELETE);
+ _add_change (fdp, fd, poll_mode_read, EV_DELETE);
+ }
- } else if ((rw == FDPOLL_MODE_READ) &&
- (fdp->fdinterest[fd] == FDPOLL_MODE_WRITE))
+ /* No longer writing */
+ if ((! (rw_mode & poll_mode_write)) &&
+ (prev_interest & poll_mode_write))
{
- _add_change (fdp, fd, FDPOLL_MODE_WRITE, EV_DELETE);
+ _add_change (fdp, fd, poll_mode_write, EV_DELETE);
}
- return _add_change (fdp, fd, rw, EV_ADD);
+ return _add_change (fdp, fd, rw_mode, EV_ADD);
}
View
86 cherokee/fdpoll-poll.c
@@ -32,7 +32,6 @@
#define POLL_READ (POLLIN | POLL_ERROR)
#define POLL_WRITE (POLLOUT | POLL_ERROR)
-
/***********************************************************************/
/* poll() */
/* */
@@ -68,9 +67,10 @@ _free (cherokee_fdpoll_poll_t *fdp)
static ret_t
-_add (cherokee_fdpoll_poll_t *fdp, int fd, int rw)
+_add (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
{
- cherokee_fdpoll_t *nfd = FDPOLL(fdp);
+ short events;
+ cherokee_fdpoll_t *nfd = FDPOLL(fdp);
/* Check the fd limit
*/
@@ -79,21 +79,20 @@ _add (cherokee_fdpoll_poll_t *fdp, int fd, int rw)
return ret_error;
}
+ /* Translate mode */
+ events = 0;
+ if (rw_mode & poll_mode_read) {
+ events |= POLLIN;
+ }
+ if (rw_mode & poll_mode_write) {
+ events |= POLLOUT;
+ }
+
+ /* Set values */
+ fdp->pollfds[nfd->npollfds].events = events;
fdp->pollfds[nfd->npollfds].fd = fd;
fdp->pollfds[nfd->npollfds].revents = 0;
- switch (rw) {
- case FDPOLL_MODE_READ:
- fdp->pollfds[nfd->npollfds].events = POLLIN;
- break;
- case FDPOLL_MODE_WRITE:
- fdp->pollfds[nfd->npollfds].events = POLLOUT;
- break;
- default:
- SHOULDNT_HAPPEN;
- return ret_error;
- }
-
fdp->fdidx[fd] = nfd->npollfds;
nfd->npollfds++;
@@ -102,9 +101,18 @@ _add (cherokee_fdpoll_poll_t *fdp, int fd, int rw)
static ret_t
-_set_mode (cherokee_fdpoll_poll_t *fdp, int fd, int rw)
+_set_mode (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
{
- fdp->pollfds[fdp->fdidx[fd]].events = (rw == FDPOLL_MODE_WRITE ? POLLOUT : POLLIN);
+ short events = 0;
+
+ if (rw_mode & poll_mode_read) {
+ events |= POLLIN;
+ }
+ if (rw_mode & poll_mode_write) {
+ events |= POLLOUT;
+ }
+
+ fdp->pollfds[fdp->fdidx[fd]].events = events;
return ret_ok;
}
@@ -150,25 +158,30 @@ _del (cherokee_fdpoll_poll_t *fdp, int fd)
static int
-_check (cherokee_fdpoll_poll_t *fdp, int fd, int rw)
+_check (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
{
int revents;
- int idx = fdp->fdidx[fd];
+ int idx = fdp->fdidx[fd];
if (idx < 0 || idx >= FDPOLL(fdp)->nfiles)
return -1;
revents = fdp->pollfds[idx].revents;
- switch (rw) {
- case FDPOLL_MODE_READ:
- return revents & POLL_READ;
- case FDPOLL_MODE_WRITE:
- return revents & POLL_WRITE;
- default:
- SHOULDNT_HAPPEN;
- return -1;
+ /* Actual result */
+ if ((rw_mode & poll_mode_read) && (revents & POLLIN)) {
+ return 1;
+ }
+ if ((rw_mode & poll_mode_write) && (revents & POLLOUT)) {
+ return 1;
+ }
+
+ /* Error */
+ if (revents & (POLLERR|POLLHUP|POLLNVAL)) {
+ return 1;
}
+
+ return 0;
}
@@ -187,11 +200,28 @@ _reset (cherokee_fdpoll_poll_t *fdp, int fd)
static int
_watch (cherokee_fdpoll_poll_t *fdp, int timeout_msecs)
{
+ int re;
+
if (unlikely (FDPOLL(fdp)->npollfds < 0)) {
SHOULDNT_HAPPEN;
}
- return poll (fdp->pollfds, FDPOLL(fdp)->npollfds, timeout_msecs);
+ re = poll (fdp->pollfds, FDPOLL(fdp)->npollfds, timeout_msecs);
+
+#if 0
+ {
+ int i;
+ cherokee_fdpoll_t *nfd = FDPOLL(fdp);
+
+ printf ("total=%d = ", nfd->npollfds);
+ for (i=0; i < nfd->npollfds; i++) {
+ printf ("fd=%d[%d,%d], ", fdp->pollfds[i].fd, fdp->pollfds[i].events, fdp->pollfds[i].revents);
+ }
+ printf ("\n");
+ }
+#endif
+
+ return re;
}
View
85 cherokee/fdpoll-port.c
@@ -32,9 +32,6 @@
#include <unistd.h>
#include <errno.h>
-#define WRITE ""
-#define READ NULL
-
#define POLL_READ (POLLIN)
#define POLL_WRITE (POLLOUT)
#define POLL_ERROR (POLLHUP | POLLERR | POLLNVAL)
@@ -70,16 +67,24 @@ typedef struct {
static ret_t
-fd_associate( cherokee_fdpoll_port_t *fdp, int fd, void *rw )
+fd_associate (cherokee_fdpoll_port_t *fdp, int fd, void *rw_mode)
{
int rc;
+ int events = 0;
- rc = port_associate (fdp->port, /* port */
- PORT_SOURCE_FD, /* source */
- fd, /* object */
- rw?POLL_WRITE:POLL_READ, /* events */
- rw); /* user data */
+ if (*rw_mode & poll_mode_read) {
+ events |= POLL_READ;
+ }
+ if (*rw_mode & poll_mode_write) {
+ events |= POLL_WRITE;
+ }
+
+ rc = port_associate (fdp->port, /* port */
+ PORT_SOURCE_FD, /* source */
+ fd, /* object */
+ events, /* events */
+ rw_mode); /* user data */
if ( rc == -1 ) {
LOG_ERRNO (errno, cherokee_err_error,
CHEROKEE_ERROR_FDPOLL_PORTS_ASSOCIATE, fd);
@@ -114,12 +119,12 @@ _free (cherokee_fdpoll_port_t *fdp)
static ret_t
-_add (cherokee_fdpoll_port_t *fdp, int fd, int rw)
+_add (cherokee_fdpoll_port_t *fdp, int fd, int rw_mode)
{
int rc;
- rc = fd_associate(fdp, fd, (rw == FDPOLL_MODE_WRITE ? WRITE : READ));
- if ( rc == -1 ) {
+ rc = fd_associate (fdp, fd, rw_mode);
+ if (rc == -1) {
LOG_ERRNO (errno, cherokee_err_error,
CHEROKEE_ERROR_FDPOLL_PORTS_FD_ASSOCIATE, fd);
return ret_error;
@@ -212,27 +217,36 @@ _watch (cherokee_fdpoll_port_t *fdp, int timeout_msecs)
static int
-_check (cherokee_fdpoll_port_t *fdp, int fd, int rw)
+_check (cherokee_fdpoll_port_t *fdp, int fd, int rw_mode)
{
- uint32_t events;
+ uint32_t events = 0;
/* Sanity check: is it a wrong fd?
*/
- if ( fd < 0 ) return -1;
+ if (unlikely (fd < 0)) {
+ return -1;
+ }
events = fdp->port_activefd[fd];
- if ( events == -1 ) return 0;
-
- switch (rw) {
- case FDPOLL_MODE_READ:
- events &= (POLL_READ | POLL_ERROR);
- break;
- case FDPOLL_MODE_WRITE:
- events &= (POLL_WRITE | POLL_ERROR);
- break;
+ if (events == -1) {
+ return 0;
+ }
+
+ /* Check
+ */
+ if ((rw_mode & poll_mode_read) && (events & POLL_READ)) {
+ return 1;
}
- return events;
+ if ((rw_mode & poll_mode_write) && (events & POLL_WRITE)) {
+ return 1;
+ }
+
+ if (events & POLL_ERROR) {
+ return 1;
+ }
+
+ return 0;
}
@@ -247,15 +261,26 @@ _reset (cherokee_fdpoll_port_t *fdp, int fd)
static ret_t
-_set_mode (cherokee_fdpoll_port_t *fdp, int fd, int rw)
+_set_mode (cherokee_fdpoll_port_t *fdp, int fd, int rw_mode)
{
int rc;
+ int events = 0;
+
+ /* Events
+ */
+ if (rw_mode & poll_mode_read) {
+ events |= POLLIN;
+ }
- rc = port_associate( fdp->port,
+ if (rw_mode & poll_mode_write) {
+ events |= POLLOUT;
+ }
+
+ /* Set it
+ */
+ rc = port_associate (fdp->port,
PORT_SOURCE_FD,
- fd,
- (rw == FDPOLL_MODE_WRITE ? POLLOUT : POLLIN),
- (rw == FDPOLL_MODE_WRITE ? WRITE : READ));
+ fd, events, rw_mode);
if ( rc == -1 ) {
LOG_ERRNO (errno, cherokee_err_error,
CHEROKEE_ERROR_FDPOLL_PORTS_ASSOCIATE, fd);
View
34 cherokee/fdpoll-select.c
@@ -87,7 +87,7 @@ _free (cherokee_fdpoll_select_t *fdp)
static ret_t
-_add (cherokee_fdpoll_select_t *fdp, int fd, int rw)
+_add (cherokee_fdpoll_select_t *fdp, int fd, int rw_mode)
{
cherokee_fdpoll_t *nfd = FDPOLL(fdp);
@@ -99,15 +99,12 @@ _add (cherokee_fdpoll_select_t *fdp, int fd, int rw)
}
fdp->select_fds[nfd->npollfds] = fd;
- switch (rw) {
- case FDPOLL_MODE_READ:
+
+ if (rw_mode & poll_mode_read) {
FD_SET (fd, &fdp->master_rfdset);
- break;
- case FDPOLL_MODE_WRITE:
+ }
+ if (rw_mode & poll_mode_write) {
FD_SET (fd, &fdp->master_wfdset);
- break;
- default:
- break;
}
if (fd > fdp->maxfd) {
@@ -115,7 +112,7 @@ _add (cherokee_fdpoll_select_t *fdp, int fd, int rw)
}
fdp->select_fdidx[fd] = nfd->npollfds;
- fdp->fd_rw[fd] = rw;
+ fdp->fd_rw[fd] = rw_mode;
nfd->npollfds++;
return ret_ok;
@@ -165,15 +162,20 @@ _set_mode (cherokee_fdpoll_select_t *fdp, int fd, int rw)
static int
-_check (cherokee_fdpoll_select_t *fdp, int fd, int rw)
+_check (cherokee_fdpoll_select_t *fdp, int fd, int rw_mode)
{
- UNUSED(rw);
+ UNUSED(rw_mode);
+
+ if ((fdp->fd_rw[fd] & poll_mode_read) &&
+ (FD_ISSET (fd, &fdp->working_rfdset)))
+ {
+ return 1;
+ }
- switch (fdp->fd_rw[fd]) {
- case FDPOLL_MODE_READ:
- return FD_ISSET (fd, &fdp->working_rfdset);
- case FDPOLL_MODE_WRITE:
- return FD_ISSET (fd, &fdp->working_wfdset);
+ if ((fdp->fd_rw[fd] & poll_mode_write) &&
+ FD_ISSET (fd, &fdp->working_wfdset))
+ {
+ return 1;
}
return 0;
View
39 cherokee/fdpoll-win32.c
@@ -78,7 +78,7 @@ _free (cherokee_fdpoll_select_t *fdp)
static ret_t
-_add (cherokee_fdpoll_select_t *fdp, int fd, int rw)
+_add (cherokee_fdpoll_select_t *fdp, int fd, int rw_mode)
{
cherokee_fdpoll_t *nfd = FDPOLL(fdp);
@@ -90,15 +90,13 @@ _add (cherokee_fdpoll_select_t *fdp, int fd, int rw)
}
fdp->select_fds[nfd->npollfds] = fd;
- switch (rw) {
- case FDPOLL_MODE_READ:
- FD_SET (fd, &fdp->master_rfdset);
- break;
- case FDPOLL_MODE_WRITE:
- FD_SET (fd, &fdp->master_wfdset);
- break;
- default:
- break;
+
+ if (rw_mode & poll_mode_read) {
+ FD_SET (fd, &fdp->master_rfdset);
+ }
+
+ if (rw_mode & poll_mode_write) {
+ FD_SET (fd, &fdp->master_wfdset);
}
if (fd > fdp->maxfd) {
@@ -140,7 +138,7 @@ _del (cherokee_fdpoll_select_t *fdp, int fd)
static ret_t
-_set_mode (cherokee_fdpoll_select_t *fdp, int fd, int rw)
+_set_mode (cherokee_fdpoll_select_t *fdp, int fd, int rw_mode)
{
ret_t ret;
@@ -148,18 +146,23 @@ _set_mode (cherokee_fdpoll_select_t *fdp, int fd, int rw)
if (unlikely(ret < ret_ok))
return ret;
- return _add (fdp, fd, rw);
+ return _add (fdp, fd, rw_mode);
}
static int
-_check (cherokee_fdpoll_select_t *fdp, int fd, int rw)
+_check (cherokee_fdpoll_select_t *fdp, int fd, int rw_mode)
{
- switch (rw) {
- case FDPOLL_MODE_READ:
- return FD_ISSET (fd, &fdp->working_rfdset);
- case FDPOLL_MODE_WRITE:
- return FD_ISSET (fd, &fdp->working_wfdset);
+ if ((rw_mode & poll_mode_read) &&
+ (FD_ISSET (fd, &fdp->working_rfdset)))
+ {
+ return 1;
+ }
+
+ if ((rw_mode & poll_mode_write) &&
+ (FD_ISSET (fd, &fdp->working_wfdset)))
+ {
+ return 1;
}
return 0;
View
8 cherokee/fdpoll.h
@@ -34,9 +34,11 @@
CHEROKEE_BEGIN_DECLS
-#define FDPOLL_MODE_NONE (-1) /* no mode set */
-#define FDPOLL_MODE_READ 0 /* poll read side */
-#define FDPOLL_MODE_WRITE 1 /* poll write side */
+typedef enum {
+ poll_mode_nothing = 0,
+ poll_mode_read = 1,
+ poll_mode_write = (1 << 1)
+} cherokee_poll_mode_t;
typedef enum {
cherokee_poll_epoll,
View
29 cherokee/handler_cgi.c
@@ -81,6 +81,7 @@ read_from_cgi (cherokee_handler_cgi_base_t *cgi_base, cherokee_buffer_t *buffer)
ret_t ret;
size_t read_ = 0;
cherokee_handler_cgi_t *cgi = HDL_CGI(cgi_base);
+ cherokee_connection_t *conn = HANDLER_CONN(cgi);
/* Sanity check: pipe() accessed
*/
@@ -95,9 +96,8 @@ read_from_cgi (cherokee_handler_cgi_base_t *cgi_base, cherokee_buffer_t *buffer)
switch (ret) {
case ret_eagain:
- cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi),
- HANDLER_CONN(cgi), cgi->pipeInput,
- FDPOLL_MODE_READ, false);
+ conn->polling_aim.fd = cgi->pipeInput;
+ conn->polling_aim.mode = poll_mode_read;
return ret_eagain;
case ret_ok:
@@ -432,17 +432,16 @@ cherokee_handler_cgi_init (cherokee_handler_cgi_t *cgi)
ret_t
cherokee_handler_cgi_read_post (cherokee_handler_cgi_t *cgi)
{
- ret_t ret;
- cherokee_connection_t *conn = HANDLER_CONN(cgi);
- cherokee_socket_status_t blocking = socket_closed;
- cherokee_boolean_t did_IO = false;
+ ret_t ret;
+ cherokee_connection_t *conn = HANDLER_CONN(cgi);
+ cherokee_boolean_t did_IO = false;
if (! conn->post.has_info) {
return ret_ok;
}
ret = cherokee_post_send_to_fd (&conn->post, &conn->socket,
- cgi->pipeOutput, NULL, &blocking, &did_IO);
+ cgi->pipeOutput, NULL, &did_IO);
if (did_IO) {
cherokee_connection_update_timeout (conn);
@@ -452,19 +451,9 @@ cherokee_handler_cgi_read_post (cherokee_handler_cgi_t *cgi)
case ret_ok:
break;
case ret_eagain:
- if (blocking == socket_writing) {
- cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi),
- conn, cgi->pipeOutput,
- FDPOLL_MODE_WRITE, false);
- return ret_deny;
- }
-
- /* ret_eagain - Block on read
- * ret_deny - Block on back-end write
+ /* conn->polling_aim.{fd,mode} was previously set by
+ * cherokee_post_send_to_fd()
*/
- if (cherokee_post_has_buffered_info (&conn->post)) {
- return ret_deny;
- }
return ret_eagain;
default:
View
29 cherokee/handler_fcgi.c
@@ -164,18 +164,14 @@ read_from_fcgi (cherokee_handler_cgi_base_t *cgi, cherokee_buffer_t *buffer)
ret_t ret;
size_t read = 0;
cherokee_handler_fcgi_t *fcgi = HDL_FCGI(cgi);
+ cherokee_connection_t *conn = HANDLER_CONN(cgi);
ret = cherokee_socket_bufread (&fcgi->socket, &fcgi->write_buffer, DEFAULT_READ_SIZE, &read);
switch (ret) {
case ret_eagain:
- ret = cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi), HANDLER_CONN(cgi),
- fcgi->socket.socket, FDPOLL_MODE_READ,
- false);
- if (unlikely (ret != ret_ok)) {
- cgi->got_eof = true;
- return ret_error;
- }
+ conn->polling_aim.fd = fcgi->socket.socket;
+ conn->polling_aim.mode = poll_mode_read;
return ret_eagain;
case ret_ok:
@@ -573,6 +569,10 @@ do_send (cherokee_handler_fcgi_t *hdl,
case ret_eagain:
if (written > 0)
break;
+
+ conn->polling_aim.fd = hdl->socket.socket;
+ conn->polling_aim.mode = poll_mode_write;
+
return ret_eagain;
default:
conn->error_code = http_bad_gateway;
@@ -648,15 +648,10 @@ send_post (cherokee_handler_fcgi_t *hdl,
cherokee_connection_update_timeout (conn);
}
- /* Block on back-end write
- */
- if (buf->len > 0) {
- return ret_deny;
- }
break;
case ret_eagain:
- /* EAGAIN on write */
- return ret_deny;
+ /* conn->polling_aim set */
+ return ret_eagain;
case ret_eof:
case ret_error:
return ret_error;
@@ -669,11 +664,7 @@ send_post (cherokee_handler_fcgi_t *hdl,
/* Next iteration
*/
if (! cherokee_buffer_is_empty (buf)) {
- cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
- HANDLER_CONN(hdl),
- hdl->socket.socket,
- FDPOLL_MODE_WRITE, false);
- return ret_deny;
+ return ret_eagain;
}
if (! cherokee_post_read_finished (&conn->post)) {
View
85 cherokee/handler_proxy.c
@@ -625,7 +625,8 @@ build_request (cherokee_handler_proxy_t *hdl,
static ret_t
do_connect (cherokee_handler_proxy_t *hdl)
{
- ret_t ret;
+ ret_t ret;
+ cherokee_connection_t *conn = HANDLER_CONN(hdl);
ret = cherokee_socket_connect (&hdl->pconn->socket);
switch (ret) {
@@ -635,13 +636,8 @@ do_connect (cherokee_handler_proxy_t *hdl)
case ret_error:
return ret;
case ret_eagain:
- ret = cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
- HANDLER_CONN(hdl),
- hdl->pconn->socket.socket,
- FDPOLL_MODE_WRITE, false);
- if (ret != ret_ok) {
- return ret_deny;
- }
+ conn->polling_aim.fd = hdl->pconn->socket.socket;
+ conn->polling_aim.mode = poll_mode_write;
return ret_eagain;
default:
RET_UNKNOWN(ret);
@@ -707,14 +703,9 @@ send_post (cherokee_handler_proxy_t *hdl)
}
TRACE (ENTRIES, "Post write: EAGAIN, wrote nothing of %d\n", buffer->len);
- ret = cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl), conn,
- hdl->pconn->socket.socket,
- FDPOLL_MODE_WRITE, false);
- if (ret != ret_ok) {
- hdl->pconn->keepalive_in = false;
- conn->error_code = http_bad_gateway;
- return ret_error;
- }
+
+ conn->polling_aim.fd = hdl->pconn->socket.socket;
+ conn->polling_aim.mode = poll_mode_write;
return ret_eagain;
default:
return ret_error;
@@ -753,14 +744,9 @@ send_post (cherokee_handler_proxy_t *hdl)
}
TRACE (ENTRIES, "Post write: EAGAIN, wrote nothing of %d\n", buffer->len);
- ret = cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl), conn,
- hdl->pconn->socket.socket,
- FDPOLL_MODE_WRITE, false);
- if (ret != ret_ok) {
- hdl->pconn->keepalive_in = false;
- conn->error_code = http_bad_gateway;
- return ret_error;
- }
+
+ conn->polling_aim.fd = hdl->pconn->socket.socket;
+ conn->polling_aim.mode = poll_mode_write;
return ret_eagain;
default:
return ret_error;
@@ -789,14 +775,9 @@ send_post (cherokee_handler_proxy_t *hdl)
}
TRACE (ENTRIES, "Post write: EAGAIN, wrote nothing of %d\n", buffer->len);
- ret = cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl), conn,
- hdl->pconn->socket.socket,
- FDPOLL_MODE_WRITE, false);
- if (ret != ret_ok) {
- hdl->pconn->keepalive_in = false;
- conn->error_code = http_bad_gateway;
- return ret_error;
- }
+
+ conn->polling_aim.fd = hdl->pconn->socket.socket;
+ conn->polling_aim.mode = poll_mode_write;
return ret_eagain;
default:
return ret_error;
@@ -847,15 +828,9 @@ send_post (cherokee_handler_proxy_t *hdl)
break;
case ret_eagain:
TRACE (ENTRIES, "Post read: EAGAIN, buffer has %d bytes\n", buffer->len);
- ret = cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
- HANDLER_CONN(hdl),
- conn->socket.socket,
- FDPOLL_MODE_READ, false);
- if (ret != ret_ok) {
- hdl->pconn->keepalive_in = false;
- conn->error_code = http_bad_gateway;
- return ret_error;
- }
+
+ conn->polling_aim.fd = conn->socket.socket;
+ conn->polling_aim.mode = poll_mode_read;
return ret_eagain;
default:
return ret;
@@ -1153,15 +1128,8 @@ cherokee_handler_proxy_init (cherokee_handler_proxy_t *hdl)
*/
break;
case ret_eagain:
- ret = cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
- HANDLER_CONN(hdl),
- hdl->pconn->socket.socket,
- FDPOLL_MODE_READ, false);
- if (ret != ret_ok) {
- hdl->pconn->keepalive_in = false;
- conn->error_code = http_bad_gateway;
- return ret_error;
- }
+ conn->polling_aim.fd = hdl->pconn->socket.socket;
+ conn->polling_aim.mode = poll_mode_read;
return ret_eagain;
case ret_eof:
case ret_error:
@@ -1657,8 +1625,9 @@ ret_t
cherokee_handler_proxy_step (cherokee_handler_proxy_t *hdl,
cherokee_buffer_t *buf)
{
- ret_t ret;
- size_t size = 0;
+ ret_t ret;
+ size_t size = 0;
+ cherokee_connection_t *conn = HANDLER_CONN(hdl);
/* No-encoding: known size
*/
@@ -1704,10 +1673,8 @@ cherokee_handler_proxy_step (cherokee_handler_proxy_t *hdl,
hdl->pconn->keepalive_in = false;
return ret;
case ret_eagain:
- cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
- HANDLER_CONN(hdl),
- hdl->pconn->socket.socket,
- FDPOLL_MODE_READ, false);
+ conn->polling_aim.fd = hdl->pconn->socket.socket;
+ conn->polling_aim.mode = poll_mode_read;
return ret_eagain;
default:
RET_UNKNOWN(ret);
@@ -1815,10 +1782,8 @@ cherokee_handler_proxy_step (cherokee_handler_proxy_t *hdl,
}
if (ret_read == ret_eagain) {
- cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
- HANDLER_CONN(hdl),
- hdl->pconn->socket.socket,
- FDPOLL_MODE_READ, false);
+ conn->polling_aim.fd = hdl->pconn->socket.socket;
+ conn->polling_aim.mode = poll_mode_read;
return ret_eagain;
}
View
29 cherokee/handler_scgi.c
@@ -140,15 +140,14 @@ read_from_scgi (cherokee_handler_cgi_base_t *cgi_base, cherokee_buffer_t *buffer
ret_t ret;
size_t read = 0;
cherokee_handler_scgi_t *scgi = HDL_SCGI(cgi_base);
+ cherokee_connection_t *conn = HANDLER_CONN(cgi_base);
ret = cherokee_socket_bufread (&scgi->socket, buffer, 4096, &read);
switch (ret) {
case ret_eagain:
- cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi_base),
- HANDLER_CONN(cgi_base),
- scgi->socket.socket,
- FDPOLL_MODE_READ, false);
+ conn->polling_aim.fd = scgi->socket.socket;
+ conn->polling_aim.mode = poll_mode_read;
return ret_eagain;
case ret_ok:
@@ -393,15 +392,14 @@ cherokee_handler_scgi_init (cherokee_handler_scgi_t *hdl)
ret_t
cherokee_handler_scgi_read_post (cherokee_handler_scgi_t *hdl)
{
- ret_t ret;
- cherokee_connection_t *conn = HANDLER_CONN(hdl);
- cherokee_socket_status_t blocking = socket_closed;
- cherokee_boolean_t did_IO = false;
+ ret_t ret;
+ cherokee_connection_t *conn = HANDLER_CONN(hdl);
+ cherokee_boolean_t did_IO = false;
/* Client Socket -> Back-end SCGI
*/
ret = cherokee_post_send_to_socket (&conn->post, &conn->socket,
- &hdl->socket, NULL, &blocking, &did_IO);
+ &hdl->socket, NULL, &did_IO);
if (did_IO) {
cherokee_connection_update_timeout (conn);
}
@@ -413,19 +411,8 @@ cherokee_handler_scgi_read_post (cherokee_handler_scgi_t *hdl)
break;
case ret_eagain:
- if (blocking == socket_writing) {
- cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
- conn, hdl->socket.socket,
- FDPOLL_MODE_WRITE, false);
- return ret_deny;
- }
-
- /* ret_eagain - Block on read
- * ret_deny - Block on back-end write
+ /* cherokee_post_send_to_socket() filled out conn->polling_aim
*/
- if (cherokee_post_has_buffered_info (&conn->post)) {
- return ret_deny;
- }
return ret_eagain;
default:
View
29 cherokee/handler_uwsgi.c
@@ -167,15 +167,14 @@ read_from_uwsgi (cherokee_handler_cgi_base_t *cgi_base,
ret_t ret;
size_t read = 0;
cherokee_handler_uwsgi_t *uwsgi = HDL_UWSGI(cgi_base);
+ cherokee_connection_t *conn = HANDLER_CONN(cgi_base);
ret = cherokee_socket_bufread (&uwsgi->socket, buffer, 4096, &read);
switch (ret) {
case ret_eagain:
- cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi_base),
- HANDLER_CONN(cgi_base),
- uwsgi->socket.socket,
- FDPOLL_MODE_READ, false);
+ conn->polling_aim.fd = uwsgi->socket.socket;
+ conn->polling_aim.mode = poll_mode_read;
return ret_eagain;
case ret_ok:
@@ -426,10 +425,9 @@ ret_t
cherokee_handler_uwsgi_read_post (cherokee_handler_uwsgi_t *hdl)
{
ret_t ret;
- cherokee_connection_t *conn = HANDLER_CONN(hdl);
- cherokee_socket_status_t blocking = socket_closed;
- cherokee_handler_uwsgi_props_t *props = HANDLER_UWSGI_PROPS(hdl);
- cherokee_boolean_t did_IO = false;
+ cherokee_connection_t *conn = HANDLER_CONN(hdl);
+ cherokee_handler_uwsgi_props_t *props = HANDLER_UWSGI_PROPS(hdl);
+ cherokee_boolean_t did_IO = false;
/* Should it send the post?
*/
@@ -440,7 +438,7 @@ cherokee_handler_uwsgi_read_post (cherokee_handler_uwsgi_t *hdl)
/* Send it
*/
ret = cherokee_post_send_to_socket (&conn->post, &conn->socket,
- &hdl->socket, NULL, &blocking, &did_IO);
+ &hdl->socket, NULL, &did_IO);
if (did_IO) {
cherokee_connection_update_timeout (conn);
@@ -451,19 +449,8 @@ cherokee_handler_uwsgi_read_post (cherokee_handler_uwsgi_t *hdl)
break;
case ret_eagain:
- if (blocking == socket_writing) {
- cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
- conn, hdl->socket.socket,
- FDPOLL_MODE_WRITE, false);
- return ret_deny;
- }
-
- /* ret_eagain - Block on read
- * ret_deny - Block on back-end write
+ /* cherokee_post_send_to_socket() filled out conn->polling_aim
*/
- if (cherokee_post_has_buffered_info (&conn->post)) {
- return ret_deny;
- }
return ret_eagain;
default:
View
86 cherokee/post.c
@@ -36,8 +36,10 @@
*/
ret_t
-cherokee_post_init (cherokee_post_t *post)
+cherokee_post_init (cherokee_post_t *post, void *conn)
{
+ post->conn = conn;
+
post->len = 0;
post->has_info = false;
post->encoding = post_enc_regular;
@@ -184,7 +186,7 @@ reply_100_continue (cherokee_post_t *post,
TRACE(ENTRIES, "Sent partial '100 Continue' response: %d bytes\n", written);
cherokee_buffer_move_to_begin (&post->read_header_100cont, written);
- return ret_eagain;
+ return ret_ok;
}
@@ -237,13 +239,12 @@ remove_surplus (cherokee_post_t *post,
ret_t
-cherokee_post_read_header (cherokee_post_t *post,
- void *cnt)
+cherokee_post_read_header (cherokee_post_t *post)
{
ret_t ret;
char *info = NULL;
cuint_t info_len = 0;
- cherokee_connection_t *conn = CONN(cnt);
+ cherokee_connection_t *conn = CONN(post->conn);
switch (post->read_header_phase) {
case cherokee_post_read_header_init:
@@ -393,8 +394,9 @@ do_read_plain (cherokee_post_t *post,
cherokee_buffer_t *buffer,
off_t to_read)
{
- ret_t ret;
- size_t len;
+ ret_t ret;
+ size_t len;
+ cherokee_connection_t *conn = CONN(post->conn);
/* Surplus from header read
*/
@@ -418,12 +420,22 @@ do_read_plain (cherokee_post_t *post,
ret = cherokee_socket_bufread (sock_in, buffer, to_read, &len);
TRACE (ENTRIES, "Post read from client: ret=%d len=%d\n", ret, len);
- if (ret != ret_ok) {
+ switch (ret) {
+ case ret_ok:
+ post->send.read += len;
+ return ret_ok;
+
+ case ret_eagain:
+ conn->polling_aim.fd = sock_in->socket;
+ conn->polling_aim.mode = poll_mode_read;
+ return ret_eagain;
+
+ default:
return ret;
}
- post->send.read += len;
- return ret_ok;
+ SHOULDNT_HAPPEN;
+ return ret_error;
}
@@ -441,6 +453,7 @@ do_read_chunked (cherokee_post_t *post,
case ret_ok:
break;
case ret_eagain:
+ /* conn->polling_aim is set */
return ret_eagain;
default:
RET_UNKNOWN(ret);
@@ -496,25 +509,30 @@ cherokee_post_read_finished (cherokee_post_t *post)
static ret_t
-do_send_socket (cherokee_socket_t *sock,
- cherokee_buffer_t *buffer,
- cherokee_socket_status_t *blocking)
+do_send_socket (cherokee_post_t *post,
+ cherokee_socket_t *sock,
+ cherokee_buffer_t *buffer)
{
- ret_t ret;
- size_t written = 0;
+ ret_t ret;
+ size_t written = 0;
+ cherokee_connection_t *conn = CONN(post->conn);
ret = cherokee_socket_bufwrite (sock, buffer, &written);
switch (ret) {
case ret_ok:
break;
+
case ret_eagain:
if (written > 0) {
break;
}
TRACE (ENTRIES, "Post write: EAGAIN, wrote nothing of %d\n", buffer->len);
- *blocking = socket_writing;
+
+ conn->polling_aim.fd = sock->socket;
+ conn->polling_aim.mode = poll_mode_write;
return ret_eagain;
+
default:
return ret_error;
}
@@ -538,12 +556,11 @@ cherokee_post_has_buffered_info (cherokee_post_t *post)
ret_t
-cherokee_post_send_to_socket (cherokee_post_t *post,
- cherokee_socket_t *sock_in,
- cherokee_socket_t *sock_out,
- cherokee_buffer_t *tmp,
- cherokee_socket_status_t *blocking,
- cherokee_boolean_t *did_IO)
+cherokee_post_send_to_socket (cherokee_post_t *post,
+ cherokee_socket_t *sock_in,
+ cherokee_socket_t *sock_out,
+ cherokee_buffer_t *tmp,
+ cherokee_boolean_t *did_IO)
{
ret_t ret;
cherokee_buffer_t *buffer = tmp ? tmp : &post->send.buffer;
@@ -559,7 +576,6 @@ cherokee_post_send_to_socket (cherokee_post_t *post,
case ret_ok:
break;
case ret_eagain:
- *blocking = socket_reading;
return ret_eagain;
default:
return ret;
@@ -578,7 +594,7 @@ cherokee_post_send_to_socket (cherokee_post_t *post,
TRACE (ENTRIES, "Post send, phase: write. Buffered: %d bytes\n", buffer->len);
if (! cherokee_buffer_is_empty (buffer)) {
- ret = do_send_socket (sock_out, buffer, blocking);
+ ret = do_send_socket (post, sock_out, buffer);
switch (ret) {
case ret_ok:
break;
@@ -620,16 +636,16 @@ cherokee_post_send_to_socket (cherokee_post_t *post,
ret_t
-cherokee_post_send_to_fd (cherokee_post_t *post,
- cherokee_socket_t *sock_in,
- int fd_out,
- cherokee_buffer_t *tmp,
- cherokee_socket_status_t *blocking,
- cherokee_boolean_t *did_IO)
+cherokee_post_send_to_fd (cherokee_post_t *post,
+ cherokee_socket_t *sock_in,
+ int fd_out,
+ cherokee_buffer_t *tmp,
+ cherokee_boolean_t *did_IO)
{
- ret_t ret;
- int r;
- cherokee_buffer_t *buffer = tmp ? tmp : &post->send.buffer;
+ ret_t ret;
+ int r;
+ cherokee_connection_t *conn = CONN(post->conn);
+ cherokee_buffer_t *buffer = tmp ? tmp : &post->send.buffer;
switch (post->send.phase) {
@@ -643,7 +659,6 @@ cherokee_post_send_to_fd (cherokee_post_t *post,
case ret_ok:
break;
case ret_eagain:
- *blocking = socket_reading;
return ret_eagain;
default:
return ret;
@@ -665,7 +680,8 @@ cherokee_post_send_to_fd (cherokee_post_t *post,
r = write (fd_out, buffer->buf, buffer->len);
if (r < 0) {
if (errno == EAGAIN) {
- *blocking = socket_writing;
+ conn->polling_aim.fd = fd_out;
+ conn->polling_aim.mode = poll_mode_write;
return ret_eagain;
}
View
49 cherokee/post.h
@@ -45,13 +45,14 @@ typedef enum {
} cherokee_post_send_phase_t;
typedef struct {
- off_t len;
- cherokee_boolean_t has_info;
- cherokee_post_encoding_t encoding;
- cherokee_post_rh_phase_t read_header_phase;
- cherokee_buffer_t read_header_100cont;
- cherokee_buffer_t header_surplus;
- cherokee_buffer_t progress_id;
+ void *conn;
+ off_t len;
+ cherokee_boolean_t has_info;
+ cherokee_post_encoding_t encoding;
+ cherokee_post_rh_phase_t read_header_phase;
+ cherokee_buffer_t read_header_100cont;
+ cherokee_buffer_t header_surplus;
+ cherokee_buffer_t progress_id;
struct {
off_t read;
@@ -73,36 +74,34 @@ typedef struct {
CHEROKEE_BEGIN_DECLS
-ret_t cherokee_post_init (cherokee_post_t *post);
+ret_t cherokee_post_init (cherokee_post_t *post, void *conn);
ret_t cherokee_post_clean (cherokee_post_t *post);
ret_t cherokee_post_mrproper (cherokee_post_t *post);
-ret_t cherokee_post_read_header (cherokee_post_t *post, void *conn);
+ret_t cherokee_post_read_header (cherokee_post_t *post);
int cherokee_post_read_finished (cherokee_post_t *post);
int cherokee_post_has_buffered_info (cherokee_post_t *post);
/* Read
*/
-ret_t cherokee_post_read (cherokee_post_t *post,
- cherokee_socket_t *sock_in,
- cherokee_buffer_t *buffer);
+ret_t cherokee_post_read (cherokee_post_t *post,
+ cherokee_socket_t *sock_in,
+ cherokee_buffer_t *buffer);
/* Read + Send
*/
-ret_t cherokee_post_send_to_socket (cherokee_post_t *post,
- cherokee_socket_t *sock_in,
- cherokee_socket_t *sock_out,
- cherokee_buffer_t *buffer,
- cherokee_socket_status_t *blocking,
- cherokee_boolean_t *did_IO);
-
-ret_t cherokee_post_send_to_fd (cherokee_post_t *post,
- cherokee_socket_t *sock_in,
- int fd_out,
- cherokee_buffer_t *tmp,
- cherokee_socket_status_t *blocking,
- cherokee_boolean_t *did_IO);
+ret_t cherokee_post_send_to_socket (cherokee_post_t *post,
+ cherokee_socket_t *sock_in,
+ cherokee_socket_t *sock_out,
+ cherokee_buffer_t *buffer,
+ cherokee_boolean_t *did_IO);
+
+ret_t cherokee_post_send_to_fd (cherokee_post_t *post,
+ cherokee_socket_t *sock_in,
+ int fd_out,
+ cherokee_buffer_t *tmp,
+ cherokee_boolean_t *did_IO);
CHEROKEE_END_DECLS
View
12 cherokee/server.c
@@ -649,7 +649,7 @@ initialize_server_threads (cherokee_server_t *srv)
list_for_each (j, &srv->listeners) {
ret = cherokee_fdpoll_add (srv->main_thread->fdpoll,
S_SOCKET_FD(BIND(j)->socket),
- FDPOLL_MODE_READ);
+ poll_mode_read);
if (ret < ret_ok)
return ret;
}
@@ -1827,21 +1827,25 @@ cherokee_server_get_conns_num (cherokee_server_t *srv, cuint_t *num)
ret_t
cherokee_server_get_active_conns (cherokee_server_t *srv, cuint_t *num)
{
+ size_t len;
cuint_t active = 0;
cherokee_list_t *thread;
/* Active connections number
*/
list_for_each (thread, &srv->thread_list) {
- active += THREAD(thread)->active_list_num;
+ len = 0;
+ cherokee_list_get_len (&THREAD(thread)->active_list, &len);
+ active += len;
}
- active += srv->main_thread->active_list_num;
+ len = 0;
+ cherokee_list_get_len (&srv->main_thread->active_list, &len);
+ active += len;
/* Return out parameters
*/
*num = active;
-
return ret_ok;
}
View
66 cherokee/socket.c
@@ -114,7 +114,7 @@ cherokee_socket_init (cherokee_socket_t *socket)
socket->client_addr_len = -1;
socket->socket = -1;
- socket->status = socket_closed;
+ socket->closed = true;
socket->is_tls = non_TLS;
socket->cryptor = NULL;
@@ -149,7 +149,7 @@ cherokee_socket_clean (cherokee_socket_t *socket)
/* Properties
*/
socket->socket = -1;
- socket->status = socket_closed;
+ socket->closed = true;
/* Client address
*/
@@ -210,7 +210,7 @@ cherokee_socket_close (cherokee_socket_t *socket)
socket->socket, socket->is_tls, (int) ret);
socket->socket = -1;
- socket->status = socket_closed;
+ socket->closed = true;
socket->is_tls = non_TLS;
return ret;
@@ -358,9 +358,9 @@ cherokee_socket_set_sockaddr (cherokee_socket_t *socket, int fd, cherokee_sockad
/* Status is no more closed.
*/
- socket->status = socket_reading;
-
+ socket->closed = false;
SOCKET_FD(socket) = fd;
+
return ret_ok;
}
@@ -698,7 +698,7 @@ cherokee_socket_write (cherokee_socket_t *socket,
#ifdef ENOTCONN
case ENOTCONN:
#endif
- socket->status = socket_closed;
+ socket->closed = true;
case ETIMEDOUT:
case EHOSTUNREACH:
return ret_error;
@@ -718,7 +718,7 @@ cherokee_socket_write (cherokee_socket_t *socket,
case ret_eagain:
return ret;
case ret_eof:
- socket->status = socket_closed;
+ socket->closed = true;
return ret_eof;
default:
RET_UNKNOWN(ret);
@@ -750,7 +750,7 @@ cherokee_socket_read (cherokee_socket_t *socket,
*/
return_if_fail (buf != NULL && buf_size > 0, ret_error);
- if (unlikely (socket->status == socket_closed)) {
+ if (unlikely (socket->closed)) {
TRACE(ENTRIES, "Reading a closed socket: fd=%d (TLS=%d)\n", SOCKET_FD(socket), (socket->is_tls == TLS));
return ret_eof;
}
@@ -768,7 +768,7 @@ cherokee_socket_read (cherokee_socket_t *socket,
}
if (len == 0) {
- socket->status = socket_closed;
+ socket->closed = true;
return ret_eof;
}
@@ -791,7 +791,7 @@ cherokee_socket_read (cherokee_socket_t *socket,
case ENOTCONN:
#endif
case ECONNRESET:
- socket->status = socket_closed;
+ socket->closed = true;
case ETIMEDOUT:
case EHOSTUNREACH:
return ret_error;
@@ -810,7 +810,7 @@ cherokee_socket_read (cherokee_socket_t *socket,
case ret_eagain:
return ret;
case ret_eof:
- socket->status = socket_closed;
+ socket->closed = true;
return ret_eof;
default:
RET_UNKNOWN(ret);
@@ -822,25 +822,6 @@ cherokee_socket_read (cherokee_socket_t *socket,
}
-int
-cherokee_socket_pending_read (cherokee_socket_t *socket)
-{
- if (socket->is_tls != TLS)
- return 0;
-
- if (unlikely ((socket->status != socket_reading) &&
- (socket->status != socket_writing)))
- return 0;
-
- if (socket->cryptor != NULL) {
- return cherokee_cryptor_socket_pending (socket->cryptor);
- }
-
- SHOULDNT_HAPPEN;
- return 0;
-}
-
-
ret_t
cherokee_socket_flush (cherokee_socket_t *socket)
{
@@ -999,7 +980,7 @@ cherokee_socket_writev (cherokee_socket_t *socket,
case ENOTCONN:
#endif
case ECONNRESET: