Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "Merge branch 'dev' of github.com:cherokee/webserver into dev"

This reverts commit 155a762, reversing
changes made to 99ef85c.
  • Loading branch information...
commit 7029d4d80d3abec13ba50fac8e7136492e07afb1 1 parent a898087
@skarcha skarcha authored
Showing with 833 additions and 796 deletions.
  1. +0 −8 admin/static/css/cherokee-admin.css
  2. +0 −2  cherokee/Makefile.am
  3. +23 −2 cherokee/bind.c
  4. +0 −58 cherokee/connection-poll.c
  5. +0 −47 cherokee/connection-poll.h
  6. +8 −6 cherokee/connection-protected.h
  7. +48 −85 cherokee/connection.c
  8. +1 −1  cherokee/connection_info.c
  9. +3 −3 cherokee/downloader_async.c
  10. +4 −0 cherokee/error_list.py
  11. +34 −45 cherokee/fdpoll-epoll.c
  12. +37 −74 cherokee/fdpoll-kqueue.c
  13. +28 −58 cherokee/fdpoll-poll.c
  14. +30 −55 cherokee/fdpoll-port.c
  15. +16 −18 cherokee/fdpoll-select.c
  16. +18 −21 cherokee/fdpoll-win32.c
  17. +3 −5 cherokee/fdpoll.h
  18. +20 −9 cherokee/handler_cgi.c
  19. +19 −10 cherokee/handler_fcgi.c
  20. +60 −25 cherokee/handler_proxy.c
  21. +21 −8 cherokee/handler_scgi.c
  22. +21 −8 cherokee/handler_uwsgi.c
  23. +35 −51 cherokee/post.c
  24. +25 −24 cherokee/post.h
  25. +4 −8 cherokee/server.c
  26. +46 −20 cherokee/socket.c
  27. +10 −8 cherokee/socket.h
  28. +8 −2 cherokee/source.c
  29. +6 −2 cherokee/source_interpreter.c
  30. +299 −132 cherokee/thread.c
  31. +6 −1 cherokee/thread.h
View
8 admin/static/css/cherokee-admin.css
@@ -426,8 +426,6 @@ img.icon_chooser_selected {
background: #235699;
background: -webkit-gradient(linear, left top, left bottom, from(#5e8bc9), to(#235699));
background: -moz-linear-gradient(top, #396aae, #235699);
- background: -o-linear-gradient(top, #396aae, #235699);
- background: linear-gradient(top, #396aae, #235699);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#396aae', endColorstr='#235699');
-moz-box-shadow: inset 1px 1px 0 #7798c2;
-webkit-box-shadow: inset 1px 1px 0 #7798c2;
@@ -440,8 +438,6 @@ img.icon_chooser_selected {
background: #24589b;
background: -webkit-gradient(linear, left top, left bottom, from(#24589b), to(#24589b));
background: -moz-linear-gradient(top, #24589b, #24589b);
- background: -o-linear-gradient(top, #24589b, #24589b);
- background: linear-gradient(top, #24589b, #24589b);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#24589b', endColorstr='#24589b');
-moz-box-shadow: inset 1px 1px 0 #24589b;
-webkit-box-shadow: inset 1px 1px 0 #24589b;
@@ -598,8 +594,6 @@ img.icon_chooser_selected {
background: #2fa42c;
background: -webkit-gradient(linear, left top, left bottom, from(#7ac25a), to(#2fa42c));
background: -moz-linear-gradient(top, #7ac25a, #2fa42c);
- background: -o-linear-gradient(top, #7ac25a, #2fa42c);
- background: linear-gradient(top, #7ac25a, #2fa42c);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#7ac25a', endColorstr='#2fa42c');
-moz-box-shadow: inset 1px 1px 0 rgba(255,255,255,0.4);
-webkit-box-shadow: inset 1px 1px 0 rgba(255,255,255,0.4);
@@ -616,8 +610,6 @@ img.icon_chooser_selected {
background: #cc0000;
background: -webkit-gradient(linear, left top, left bottom, from(#ff8888), to(#cc0000));
background: -moz-linear-gradient(top, #ff8888, #cc0000);
- background: -o-linear-gradient(top, #ff8888, #cc0000);
- background: linear-gradient(top, #ff8888, #cc0000);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff8888', endColorstr='#cc0000');
-moz-box-shadow: inset 1px 1px 0 rgba(255,255,255,0.4);
-webkit-box-shadow: inset 1px 1px 0 rgba(255,255,255,0.4);
View
2  cherokee/Makefile.am
@@ -1577,8 +1577,6 @@ $(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,12 +171,33 @@ 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.
+ * attempts TCP will make to complete the connection. This option should
+ * not be used in code intended to be portable.
*
- * Gives clients 5secs to send the first data packet
+ * Give clients 5s to send first data packet
*/
#ifdef TCP_DEFER_ACCEPT
on = 5;
View
58 cherokee/connection-poll.c
@@ -1,58 +0,0 @@
-/* -*- 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
@@ -1,47 +0,0 @@
-/* -*- 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,7 +68,6 @@
#include "bind.h"
#include "bogotime.h"
#include "config_entry.h"
-#include "connection-poll.h"
typedef enum {
phase_nothing,
@@ -90,9 +89,10 @@ 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_cant_encoder (1 << 4)
-#define conn_op_got_eof (1 << 5)
-#define conn_op_chunked_formatted (1 << 6)
+#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)
typedef cuint_t cherokee_connection_options_t;
@@ -192,7 +192,9 @@ struct cherokee_connection {
/* Polling
*/
- cherokee_connection_pool_t polling_aim;
+ int polling_fd;
+ cherokee_socket_status_t polling_mode;
+ cherokee_boolean_t polling_multiple;
off_t range_start;
off_t range_end;
@@ -252,7 +254,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, cherokee_boolean_t reuse);
+ret_t cherokee_connection_clean (cherokee_connection_t *conn);
ret_t cherokee_connection_clean_close (cherokee_connection_t *conn);
/* Close
View
133 cherokee/connection.c
@@ -120,6 +120,9 @@ 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;
@@ -155,8 +158,7 @@ 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, n);
- cherokee_connection_poll_init (&n->polling_aim);
+ cherokee_post_init (&n->post);
memset (n->regex_ovector, 0, OVECTOR_LEN * sizeof(int));
n->regex_ovecsize = 0;
@@ -230,11 +232,11 @@ cherokee_connection_free (cherokee_connection_t *conn)
conn->arguments = NULL;
}
-
- if (conn->polling_aim.fd != -1) {
- cherokee_fd_close (conn->polling_aim.fd);
- }
- cherokee_connection_poll_mrproper (&conn->polling_aim);
+ if (conn->polling_fd != -1) {
+ cherokee_fd_close (conn->polling_fd);
+ conn->polling_fd = -1;
+ conn->polling_mode = FDPOLL_MODE_NONE;
+ }
free (conn);
return ret_ok;
@@ -242,8 +244,7 @@ cherokee_connection_free (cherokee_connection_t *conn)
ret_t
-cherokee_connection_clean (cherokee_connection_t *conn,
- cherokee_boolean_t reuse)
+cherokee_connection_clean (cherokee_connection_t *conn)
{
size_t crlf_len;
uint32_t header_len;
@@ -288,10 +289,10 @@ cherokee_connection_clean (cherokee_connection_t *conn,
conn->encoder_new_func = NULL;
conn->encoder_props = NULL;
- if (conn->polling_aim.fd != -1) {
- cherokee_fd_close (conn->polling_aim.fd);
+ if (conn->polling_fd != -1) {
+ cherokee_fd_close (conn->polling_fd);
+ conn->polling_fd = -1;
}
- cherokee_connection_poll_clean (&conn->polling_aim);
if (conn->validator != NULL) {
cherokee_validator_free (conn->validator);
@@ -314,6 +315,8 @@ 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;
@@ -330,8 +333,6 @@ 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);
@@ -372,24 +373,27 @@ cherokee_connection_clean (cherokee_connection_t *conn,
cherokee_buffer_clean (&conn->buffer);
cherokee_buffer_clean (&conn->header_buffer);
- 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;
+ /* 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);
- 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);
+ /* 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, has headers %d\n", conn,
+ !cherokee_buffer_is_empty (&conn->incoming_header));
+
return ret_ok;
}
@@ -409,7 +413,7 @@ cherokee_connection_clean_close (cherokee_connection_t *conn)
/* Clean the connection object
*/
- cherokee_connection_clean (conn, false);
+ cherokee_connection_clean (conn);
return ret_ok;
}
@@ -1053,12 +1057,8 @@ 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:
- conn->polling_aim.fd = conn->socket.socket;
- conn->polling_aim.mode = poll_mode_write;
- return ret_eagain;
+ return ret;
case ret_error:
conn->keepalive = 0;
@@ -1095,12 +1095,8 @@ cherokee_connection_send_header_and_mmaped (cherokee_connection_t *conn)
switch (ret) {
case ret_eof:
- return ret_eof;
-
case ret_eagain:
- conn->polling_aim.fd = conn->socket.socket;
- conn->polling_aim.mode = poll_mode_write;
- return ret_eagain;
+ return ret;
case ret_error:
conn->keepalive = 0;
@@ -1192,15 +1188,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:
@@ -1258,18 +1254,7 @@ cherokee_connection_send_header (cherokee_connection_t *conn)
/* Send the buffer content
*/
ret = cherokee_socket_bufwrite (&conn->socket, &conn->buffer, &sent);
- 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;
- }
+ if (unlikely(ret != ret_ok)) return ret;
/* Add to the connection traffic counter
*/
@@ -1355,12 +1340,8 @@ cherokee_connection_send (cherokee_connection_t *conn)
break;
case ret_eof:
- return ret_eof;
-
case ret_eagain:
- conn->polling_aim.fd = conn->socket.socket;
- conn->polling_aim.mode = poll_mode_write;
- return ret_eagain;
+ return ret;
case ret_error:
conn->keepalive = 0;
@@ -1398,18 +1379,8 @@ cherokee_connection_send (cherokee_connection_t *conn)
}
ret = cherokee_socket_write (&conn->socket, conn->buffer.buf, to_send, &sent);
- 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:
+ if (unlikely(ret != ret_ok))
return ret;
- }
/* Drop out the sent info
*/
@@ -1552,17 +1523,12 @@ 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 %s closed\n", conn->socket.closed ? "is" : "isn't");
+ TRACE(ENTRIES",linger", "Linger read, socket status %d\n", conn->socket.status);
while (true) {
/* Read from the socket to nowhere
*/
- ret = cherokee_socket_read (&conn->socket, tmp1->buf, tmp1->size - 1, &cnt_read);
-
- if (cnt_read > 0) {
- cherokee_buffer_clean (tmp1);
- }
-
+ ret = cherokee_socket_read (&conn->socket, tmp1->buf, tmp1->size, &cnt_read);
switch (ret) {
case ret_eof:
TRACE (ENTRIES",linger", "%s\n", "EOF");
@@ -1572,17 +1538,12 @@ 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 - 2) && (retries > 0))
+ if (cnt_read == tmp1->size && retries > 0)
continue;
-
return ret_eof;
default:
RET_UNKNOWN(ret);
@@ -2215,7 +2176,7 @@ cherokee_connection_get_request (cherokee_connection_t *conn)
*/
if (read_post)
{
- ret = cherokee_post_read_header (&conn->post);
+ ret = cherokee_post_read_header (&conn->post, conn);
if (unlikely (ret != ret_ok)) {
return ret;
}
@@ -2897,6 +2858,8 @@ 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 (cherokee_list_empty (&thread->active_list))
+ if (thread->active_list_num <= 0)
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, poll_mode_write);
+ ret = cherokee_fdpoll_add (fdpoll, down->socket.socket, FDPOLL_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 = poll_mode_write;
+ rw = FDPOLL_MODE_WRITE;
else
- rw = poll_mode_read;
+ rw = FDPOLL_MODE_READ;
TRACE(ENTRIES, "rw = %d\n", rw);
View
4 cherokee/error_list.py
@@ -904,6 +904,10 @@
# 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
79 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 mode_rw)
+_add (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
{
struct epoll_event ev;
@@ -94,20 +94,16 @@ _add (cherokee_fdpoll_epoll_t *fdp, int fd, int mode_rw)
/* Add the new descriptor
*/
ev.data.u64 = 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)) {
+ 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;
SHOULDNT_HAPPEN;
return ret_error;
}
@@ -128,6 +124,10 @@ _del (cherokee_fdpoll_epoll_t *fdp, int fd)
{
struct epoll_event ev;
+ ev.events = 0;
+ ev.data.u64 = 0; /* <- I just wanna be sure there aren't */
+ ev.data.fd = fd; /* <- 4 bytes uninitialized */
+
/* Check the fd limit
*/
if (unlikely (cherokee_fdpoll_is_empty (FDPOLL(fdp)))) {
@@ -147,7 +147,7 @@ _del (cherokee_fdpoll_epoll_t *fdp, int fd)
static int
-_check (cherokee_fdpoll_epoll_t *fdp, int fd, int rw_mode)
+_check (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
{
int fdidx;
uint32_t events;
@@ -181,19 +181,14 @@ _check (cherokee_fdpoll_epoll_t *fdp, int fd, int rw_mode)
*/
events = fdp->ep_events[fdidx].events;
- 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;
+ switch (rw) {
+ case FDPOLL_MODE_READ:
+ return events & (EPOLLIN | EPOLLERR | EPOLLHUP);
+ case FDPOLL_MODE_WRITE:
+ return events & (EPOLLOUT | EPOLLERR | EPOLLHUP);
+ default:
+ return -1;
}
-
- return -1;
}
@@ -212,36 +207,30 @@ _reset (cherokee_fdpoll_epoll_t *fdp, int fd)
static ret_t
-_set_mode (cherokee_fdpoll_epoll_t *fdp, int fd, int rw_mode)
+_set_mode (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
{
struct epoll_event ev;
ev.data.u64 = 0;
ev.data.fd = fd;
- 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)) {
+ switch (rw) {
+ case FDPOLL_MODE_READ:
+ ev.events = EPOLLIN;
+ break;
+ case FDPOLL_MODE_WRITE:
+ ev.events = EPOLLOUT;
+ break;
+ default:
+ ev.events = 0;
return ret_error;
}
- /* Apply it
- */
- if (epoll_ctl (fdp->ep_fd, EPOLL_CTL_MOD, fd, &ev) < 0) {
+ 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,15 +91,11 @@ _free (cherokee_fdpoll_kqueue_t *fdp)
static ret_t
-_add_change (cherokee_fdpoll_kqueue_t *fdp, int fd, int mode, int change)
+_add_change(cherokee_fdpoll_kqueue_t *fdp, int fd, int rw, 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");
@@ -108,23 +104,21 @@ _add_change (cherokee_fdpoll_kqueue_t *fdp, int fd, int mode, int change)
event = &fdp->changelist[index];
event->ident = fd;
-
- switch (mode) {
- case poll_mode_read:
+ switch (rw) {
+ case FDPOLL_MODE_READ:
event->filter = EVFILT_READ;
break;
- case poll_mode_write:
+ case FDPOLL_MODE_WRITE:
event->filter = EVFILT_WRITE;
break;
default:
- event->filter = 0;
SHOULDNT_HAPPEN;
- }
+ }
event->flags = change;
event->fflags = 0;
- fdp->fdinterest[fd] = mode;
+ fdp->fdinterest[fd] = rw;
fdp->nchanges++;
return ret_ok;
@@ -132,55 +126,30 @@ _add_change (cherokee_fdpoll_kqueue_t *fdp, int fd, int mode, int change)
static ret_t
-_add (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw_mode)
+_add (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw)
{
- 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;
- }
+ int re;
- 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) {
+ re = _add_change (fdp, fd, rw, EV_ADD);
+ if (re == ret_ok) {
FDPOLL(fdp)->npollfds++;
}
- return ret;
+ return re;
}
static ret_t
_del (cherokee_fdpoll_kqueue_t *fdp, int fd)
{
- 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;
- }
+ int re;
- 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)) {
+ re = _add_change (fdp, fd, fdp->fdinterest[fd], EV_DELETE);
+ if (re == ret_ok) {
FDPOLL(fdp)->npollfds--;
}
- fdp->fdinterest[fd] = 0;
- return ret;
+ return re;
}
@@ -214,7 +183,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) {
@@ -238,7 +207,7 @@ _watch (cherokee_fdpoll_kqueue_t *fdp, int timeout_msecs)
}
static int
-_check (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw_mode)
+_check (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw)
{
uint32_t events;
@@ -254,16 +223,15 @@ _check (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw_mode)
return 1;
}
- if ((rw_mode & poll_mode_read) &&
- (events & KQUEUE_READ_EVENT))
- {
- return 1;
- }
-
- if ((rw_mode & poll_mode_write) &&
- (events & KQUEUE_WRITE_EVENT))
- {
- 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;
}
return events;
@@ -281,29 +249,24 @@ _reset (cherokee_fdpoll_kqueue_t *fdp, int fd)
static ret_t
-_set_mode (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw_mode)
+_set_mode (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw)
{
- 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 transitioning from r -> w or from w -> r
+ * disable any active event on the fd as we are
+ * no longer interested on it.
*/
-
- /* No longer reading */
- if ((! (rw_mode & poll_mode_read)) &&
- (prev_interest & poll_mode_read))
+ if ((rw == FDPOLL_MODE_WRITE) &&
+ (fdp->fdinterest[fd] == FDPOLL_MODE_READ))
{
- _add_change (fdp, fd, poll_mode_read, EV_DELETE);
- }
+ _add_change (fdp, fd, FDPOLL_MODE_READ, EV_DELETE);
- /* No longer writing */
- if ((! (rw_mode & poll_mode_write)) &&
- (prev_interest & poll_mode_write))
+ } else if ((rw == FDPOLL_MODE_READ) &&
+ (fdp->fdinterest[fd] == FDPOLL_MODE_WRITE))
{
- _add_change (fdp, fd, poll_mode_write, EV_DELETE);
+ _add_change (fdp, fd, FDPOLL_MODE_WRITE, EV_DELETE);
}
- return _add_change (fdp, fd, rw_mode, EV_ADD);
+ return _add_change (fdp, fd, rw, EV_ADD);
}
View
86 cherokee/fdpoll-poll.c
@@ -32,6 +32,7 @@
#define POLL_READ (POLLIN | POLL_ERROR)
#define POLL_WRITE (POLLOUT | POLL_ERROR)
+
/***********************************************************************/
/* poll() */
/* */
@@ -67,10 +68,9 @@ _free (cherokee_fdpoll_poll_t *fdp)
static ret_t
-_add (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
+_add (cherokee_fdpoll_poll_t *fdp, int fd, int rw)
{
- short events;
- cherokee_fdpoll_t *nfd = FDPOLL(fdp);
+ cherokee_fdpoll_t *nfd = FDPOLL(fdp);
/* Check the fd limit
*/
@@ -79,20 +79,21 @@ _add (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
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++;
@@ -101,18 +102,9 @@ _add (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
static ret_t
-_set_mode (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
+_set_mode (cherokee_fdpoll_poll_t *fdp, int fd, int rw)
{
- 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;
+ fdp->pollfds[fdp->fdidx[fd]].events = (rw == FDPOLL_MODE_WRITE ? POLLOUT : POLLIN);
return ret_ok;
}
@@ -158,30 +150,25 @@ _del (cherokee_fdpoll_poll_t *fdp, int fd)
static int
-_check (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
+_check (cherokee_fdpoll_poll_t *fdp, int fd, int rw)
{
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;
- /* 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;
+ switch (rw) {
+ case FDPOLL_MODE_READ:
+ return revents & POLL_READ;
+ case FDPOLL_MODE_WRITE:
+ return revents & POLL_WRITE;
+ default:
+ SHOULDNT_HAPPEN;
+ return -1;
}
-
- return 0;
}
@@ -200,28 +187,11 @@ _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;
}
- 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;
+ return poll (fdp->pollfds, FDPOLL(fdp)->npollfds, timeout_msecs);
}
View
85 cherokee/fdpoll-port.c
@@ -32,6 +32,9 @@
#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)
@@ -67,24 +70,16 @@ typedef struct {
static ret_t
-fd_associate (cherokee_fdpoll_port_t *fdp, int fd, void *rw_mode)
+fd_associate( cherokee_fdpoll_port_t *fdp, int fd, void *rw )
{
int rc;
- int events = 0;
- if (*rw_mode & poll_mode_read) {
- events |= POLL_READ;
- }
+ 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_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);
@@ -119,12 +114,12 @@ _free (cherokee_fdpoll_port_t *fdp)
static ret_t
-_add (cherokee_fdpoll_port_t *fdp, int fd, int rw_mode)
+_add (cherokee_fdpoll_port_t *fdp, int fd, int rw)
{
int rc;
- rc = fd_associate (fdp, fd, rw_mode);
- if (rc == -1) {
+ rc = fd_associate(fdp, fd, (rw == FDPOLL_MODE_WRITE ? WRITE : READ));
+ if ( rc == -1 ) {
LOG_ERRNO (errno, cherokee_err_error,
CHEROKEE_ERROR_FDPOLL_PORTS_FD_ASSOCIATE, fd);
return ret_error;
@@ -217,36 +212,27 @@ _watch (cherokee_fdpoll_port_t *fdp, int timeout_msecs)
static int
-_check (cherokee_fdpoll_port_t *fdp, int fd, int rw_mode)
+_check (cherokee_fdpoll_port_t *fdp, int fd, int rw)
{
- uint32_t events = 0;
+ uint32_t events;
/* Sanity check: is it a wrong fd?
*/
- if (unlikely (fd < 0)) {
- return -1;
- }
+ if ( fd < 0 ) return -1;
events = fdp->port_activefd[fd];
- if (events == -1) {
- return 0;
- }
-
- /* Check
- */
- if ((rw_mode & poll_mode_read) && (events & POLL_READ)) {
- return 1;
+ 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 ((rw_mode & poll_mode_write) && (events & POLL_WRITE)) {
- return 1;
- }
-
- if (events & POLL_ERROR) {
- return 1;
- }
-
- return 0;
+ return events;
}
@@ -261,26 +247,15 @@ _reset (cherokee_fdpoll_port_t *fdp, int fd)
static ret_t
-_set_mode (cherokee_fdpoll_port_t *fdp, int fd, int rw_mode)
+_set_mode (cherokee_fdpoll_port_t *fdp, int fd, int rw)
{
int rc;
- int events = 0;
-
- /* Events
- */
- if (rw_mode & poll_mode_read) {
- events |= POLLIN;
- }
- if (rw_mode & poll_mode_write) {
- events |= POLLOUT;
- }
-
- /* Set it
- */
- rc = port_associate (fdp->port,
+ rc = port_associate( fdp->port,
PORT_SOURCE_FD,
- fd, events, rw_mode);
+ fd,
+ (rw == FDPOLL_MODE_WRITE ? POLLOUT : POLLIN),
+ (rw == FDPOLL_MODE_WRITE ? WRITE : READ));
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_mode)
+_add (cherokee_fdpoll_select_t *fdp, int fd, int rw)
{
cherokee_fdpoll_t *nfd = FDPOLL(fdp);
@@ -99,12 +99,15 @@ _add (cherokee_fdpoll_select_t *fdp, int fd, int rw_mode)
}
fdp->select_fds[nfd->npollfds] = fd;
-
- if (rw_mode & poll_mode_read) {
+ switch (rw) {
+ case FDPOLL_MODE_READ:
FD_SET (fd, &fdp->master_rfdset);
- }
- if (rw_mode & poll_mode_write) {
+ break;
+ case FDPOLL_MODE_WRITE:
FD_SET (fd, &fdp->master_wfdset);
+ break;
+ default:
+ break;
}
if (fd > fdp->maxfd) {
@@ -112,7 +115,7 @@ _add (cherokee_fdpoll_select_t *fdp, int fd, int rw_mode)
}
fdp->select_fdidx[fd] = nfd->npollfds;
- fdp->fd_rw[fd] = rw_mode;
+ fdp->fd_rw[fd] = rw;
nfd->npollfds++;
return ret_ok;
@@ -162,20 +165,15 @@ _set_mode (cherokee_fdpoll_select_t *fdp, int fd, int rw)
static int
-_check (cherokee_fdpoll_select_t *fdp, int fd, int rw_mode)
+_check (cherokee_fdpoll_select_t *fdp, int fd, int rw)
{
- UNUSED(rw_mode);
-
- if ((fdp->fd_rw[fd] & poll_mode_read) &&
- (FD_ISSET (fd, &fdp->working_rfdset)))
- {
- return 1;
- }
+ UNUSED(rw);
- if ((fdp->fd_rw[fd] & poll_mode_write) &&
- FD_ISSET (fd, &fdp->working_wfdset))
- {
- 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);
}
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_mode)
+_add (cherokee_fdpoll_select_t *fdp, int fd, int rw)
{
cherokee_fdpoll_t *nfd = FDPOLL(fdp);
@@ -90,13 +90,15 @@ _add (cherokee_fdpoll_select_t *fdp, int fd, int rw_mode)
}
fdp->select_fds[nfd->npollfds] = fd;
-
- if (rw_mode & poll_mode_read) {
- FD_SET (fd, &fdp->master_rfdset);
- }
-
- if (rw_mode & poll_mode_write) {
- FD_SET (fd, &fdp->master_wfdset);
+ 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 (fd > fdp->maxfd) {
@@ -138,7 +140,7 @@ _del (cherokee_fdpoll_select_t *fdp, int fd)
static ret_t
-_set_mode (cherokee_fdpoll_select_t *fdp, int fd, int rw_mode)
+_set_mode (cherokee_fdpoll_select_t *fdp, int fd, int rw)
{
ret_t ret;
@@ -146,23 +148,18 @@ _set_mode (cherokee_fdpoll_select_t *fdp, int fd, int rw_mode)
if (unlikely(ret < ret_ok))
return ret;
- return _add (fdp, fd, rw_mode);
+ return _add (fdp, fd, rw);
}
static int
-_check (cherokee_fdpoll_select_t *fdp, int fd, int rw_mode)
+_check (cherokee_fdpoll_select_t *fdp, int fd, int rw)
{
- 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;
+ switch (rw) {
+ case FDPOLL_MODE_READ:
+ return FD_ISSET (fd, &fdp->working_rfdset);
+ case FDPOLL_MODE_WRITE:
+ return FD_ISSET (fd, &fdp->working_wfdset);
}
return 0;
View
8 cherokee/fdpoll.h
@@ -34,11 +34,9 @@
CHEROKEE_BEGIN_DECLS
-typedef enum {
- poll_mode_nothing = 0,
- poll_mode_read = 1,
- poll_mode_write = (1 << 1)
-} cherokee_poll_mode_t;
+#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 {
cherokee_poll_epoll,
View
29 cherokee/handler_cgi.c
@@ -81,7 +81,6 @@ 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
*/
@@ -96,8 +95,9 @@ read_from_cgi (cherokee_handler_cgi_base_t *cgi_base, cherokee_buffer_t *buffer)
switch (ret) {
case ret_eagain:
- conn->polling_aim.fd = cgi->pipeInput;
- conn->polling_aim.mode = poll_mode_read;
+ cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi),
+ HANDLER_CONN(cgi), cgi->pipeInput,
+ FDPOLL_MODE_READ, false);
return ret_eagain;
case ret_ok:
@@ -432,16 +432,17 @@ 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_boolean_t did_IO = false;
+ ret_t ret;
+ cherokee_connection_t *conn = HANDLER_CONN(cgi);
+ cherokee_socket_status_t blocking = socket_closed;
+ 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, &did_IO);
+ cgi->pipeOutput, NULL, &blocking, &did_IO);
if (did_IO) {
cherokee_connection_update_timeout (conn);
@@ -451,9 +452,19 @@ cherokee_handler_cgi_read_post (cherokee_handler_cgi_t *cgi)
case ret_ok:
break;
case ret_eagain:
- /* conn->polling_aim.{fd,mode} was previously set by
- * cherokee_post_send_to_fd()
+ 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
*/
+ if (cherokee_post_has_buffered_info (&conn->post)) {
+ return ret_deny;
+ }
return ret_eagain;
default:
View
29 cherokee/handler_fcgi.c
@@ -164,14 +164,18 @@ 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:
- conn->polling_aim.fd = fcgi->socket.socket;
- conn->polling_aim.mode = poll_mode_read;
+ 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;
+ }
return ret_eagain;
case ret_ok:
@@ -569,10 +573,6 @@ 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,10 +648,15 @@ 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:
- /* conn->polling_aim set */
- return ret_eagain;
+ /* EAGAIN on write */
+ return ret_deny;
case ret_eof:
case ret_error:
return ret_error;
@@ -664,7 +669,11 @@ send_post (cherokee_handler_fcgi_t *hdl,
/* Next iteration
*/
if (! cherokee_buffer_is_empty (buf)) {
- return ret_eagain;
+ cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
+ HANDLER_CONN(hdl),
+ hdl->socket.socket,
+ FDPOLL_MODE_WRITE, false);
+ return ret_deny;
}
if (! cherokee_post_read_finished (&conn->post)) {
View
85 cherokee/handler_proxy.c
@@ -625,8 +625,7 @@ build_request (cherokee_handler_proxy_t *hdl,
static ret_t
do_connect (cherokee_handler_proxy_t *hdl)
{
- ret_t ret;
- cherokee_connection_t *conn = HANDLER_CONN(hdl);
+ ret_t ret;
ret = cherokee_socket_connect (&hdl->pconn->socket);
switch (ret) {
@@ -636,8 +635,13 @@ do_connect (cherokee_handler_proxy_t *hdl)
case ret_error:
return ret;
case ret_eagain:
- conn->polling_aim.fd = hdl->pconn->socket.socket;
- conn->polling_aim.mode = poll_mode_write;
+ 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;
+ }
return ret_eagain;
default:
RET_UNKNOWN(ret);
@@ -703,9 +707,14 @@ send_post (cherokee_handler_proxy_t *hdl)
}
TRACE (ENTRIES, "Post write: EAGAIN, wrote nothing of %d\n", buffer->len);
-
- conn->polling_aim.fd = hdl->pconn->socket.socket;
- conn->polling_aim.mode = poll_mode_write;
+ 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;
+ }
return ret_eagain;
default:
return ret_error;
@@ -744,9 +753,14 @@ send_post (cherokee_handler_proxy_t *hdl)
}
TRACE (ENTRIES, "Post write: EAGAIN, wrote nothing of %d\n", buffer->len);
-
- conn->polling_aim.fd = hdl->pconn->socket.socket;
- conn->polling_aim.mode = poll_mode_write;
+ 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;
+ }
return ret_eagain;
default:
return ret_error;
@@ -775,9 +789,14 @@ send_post (cherokee_handler_proxy_t *hdl)
}
TRACE (ENTRIES, "Post write: EAGAIN, wrote nothing of %d\n", buffer->len);
-
- conn->polling_aim.fd = hdl->pconn->socket.socket;
- conn->polling_aim.mode = poll_mode_write;
+ 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;
+ }
return ret_eagain;
default:
return ret_error;
@@ -828,9 +847,15 @@ send_post (cherokee_handler_proxy_t *hdl)
break;
case ret_eagain:
TRACE (ENTRIES, "Post read: EAGAIN, buffer has %d bytes\n", buffer->len);
-
- conn->polling_aim.fd = conn->socket.socket;
- conn->polling_aim.mode = poll_mode_read;
+ 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;
+ }
return ret_eagain;
default:
return ret;
@@ -1128,8 +1153,15 @@ cherokee_handler_proxy_init (cherokee_handler_proxy_t *hdl)
*/
break;
case ret_eagain:
- conn->polling_aim.fd = hdl->pconn->socket.socket;
- conn->polling_aim.mode = poll_mode_read;
+ 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;
+ }
return ret_eagain;
case ret_eof:
case ret_error:
@@ -1625,9 +1657,8 @@ ret_t
cherokee_handler_proxy_step (cherokee_handler_proxy_t *hdl,
cherokee_buffer_t *buf)
{
- ret_t ret;
- size_t size = 0;
- cherokee_connection_t *conn = HANDLER_CONN(hdl);
+ ret_t ret;
+ size_t size = 0;
/* No-encoding: known size
*/
@@ -1673,8 +1704,10 @@ cherokee_handler_proxy_step (cherokee_handler_proxy_t *hdl,
hdl->pconn->keepalive_in = false;
return ret;
case ret_eagain:
- conn->polling_aim.fd = hdl->pconn->socket.socket;
- conn->polling_aim.mode = poll_mode_read;
+ cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
+ HANDLER_CONN(hdl),
+ hdl->pconn->socket.socket,
+ FDPOLL_MODE_READ, false);
return ret_eagain;
default:
RET_UNKNOWN(ret);
@@ -1782,8 +1815,10 @@ cherokee_handler_proxy_step (cherokee_handler_proxy_t *hdl,
}
if (ret_read == ret_eagain) {
- conn->polling_aim.fd = hdl->pconn->socket.socket;
- conn->polling_aim.mode = poll_mode_read;
+ cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
+ HANDLER_CONN(hdl),
+ hdl->pconn->socket.socket,
+ FDPOLL_MODE_READ, false);
return ret_eagain;
}
View
29 cherokee/handler_scgi.c
@@ -140,14 +140,15 @@ 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:
- conn->polling_aim.fd = scgi->socket.socket;
- conn->polling_aim.mode = poll_mode_read;
+ cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi_base),
+ HANDLER_CONN(cgi_base),
+ scgi->socket.socket,
+ FDPOLL_MODE_READ, false);
return ret_eagain;
case ret_ok:
@@ -392,14 +393,15 @@ 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_boolean_t did_IO = false;
+ ret_t ret;
+ cherokee_connection_t *conn = HANDLER_CONN(hdl);
+ cherokee_socket_status_t blocking = socket_closed;
+ cherokee_boolean_t did_IO = false;
/* Client Socket -> Back-end SCGI
*/
ret = cherokee_post_send_to_socket (&conn->post, &conn->socket,
- &hdl->socket, NULL, &did_IO);
+ &hdl->socket, NULL, &blocking, &did_IO);
if (did_IO) {
cherokee_connection_update_timeout (conn);
}
@@ -411,8 +413,19 @@ cherokee_handler_scgi_read_post (cherokee_handler_scgi_t *hdl)
break;
case ret_eagain:
- /* cherokee_post_send_to_socket() filled out conn->polling_aim
+ 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
*/
+ if (cherokee_post_has_buffered_info (&conn->post)) {
+ return ret_deny;
+ }
return ret_eagain;
default:
View
29 cherokee/handler_uwsgi.c
@@ -167,14 +167,15 @@ 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:
- conn->polling_aim.fd = uwsgi->socket.socket;
- conn->polling_aim.mode = poll_mode_read;
+ cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi_base),
+ HANDLER_CONN(cgi_base),
+ uwsgi->socket.socket,
+ FDPOLL_MODE_READ, false);
return ret_eagain;
case ret_ok:
@@ -425,9 +426,10 @@ ret_t
cherokee_handler_uwsgi_read_post (cherokee_handler_uwsgi_t *hdl)
{
ret_t ret;
- cherokee_connection_t *conn = HANDLER_CONN(hdl);
- cherokee_handler_uwsgi_props_t *props = HANDLER_UWSGI_PROPS(hdl);
- cherokee_boolean_t did_IO = false;
+ 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;
/* Should it send the post?
*/
@@ -438,7 +440,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, &did_IO);
+ &hdl->socket, NULL, &blocking, &did_IO);
if (did_IO) {
cherokee_connection_update_timeout (conn);
@@ -449,8 +451,19 @@ cherokee_handler_uwsgi_read_post (cherokee_handler_uwsgi_t *hdl)
break;
case ret_eagain:
- /* cherokee_post_send_to_socket() filled out conn->polling_aim
+ 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
*/
+ if (cherokee_post_has_buffered_info (&conn->post)) {
+ return ret_deny;
+ }
return ret_eagain;
default:
View
86 cherokee/post.c
@@ -36,10 +36,8 @@
*/
ret_t
-cherokee_post_init (cherokee_post_t *post, void *conn)
+cherokee_post_init (cherokee_post_t *post)
{
- post->conn = conn;
-
post->len = 0;
post->has_info = false;
post->encoding = post_enc_regular;
@@ -186,7 +184,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_ok;
+ return ret_eagain;
}
@@ -239,12 +237,13 @@ remove_surplus (cherokee_post_t *post,
ret_t
-cherokee_post_read_header (cherokee_post_t *post)
+cherokee_post_read_header (cherokee_post_t *post,
+ void *cnt)
{
ret_t ret;
char *info = NULL;
cuint_t info_len = 0;
- cherokee_connection_t *conn = CONN(post->conn);
+ cherokee_connection_t *conn = CONN(cnt);
switch (post->read_header_phase) {
case cherokee_post_read_header_init:
@@ -394,9 +393,8 @@ do_read_plain (cherokee_post_t *post,
cherokee_buffer_t *buffer,
off_t to_read)
{
- ret_t ret;
- size_t len;
- cherokee_connection_t *conn = CONN(post->conn);
+ ret_t ret;
+ size_t len;
/* Surplus from header read
*/
@@ -420,22 +418,12 @@ 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);
- 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:
+ if (ret != ret_ok) {
return ret;
}
- SHOULDNT_HAPPEN;
- return ret_error;
+ post->send.read += len;
+ return ret_ok;
}
@@ -453,7 +441,6 @@ 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);
@@ -509,30 +496,25 @@ cherokee_post_read_finished (cherokee_post_t *post)
static ret_t
-do_send_socket (cherokee_post_t *post,
- cherokee_socket_t *sock,
- cherokee_buffer_t *buffer)
+do_send_socket (cherokee_socket_t *sock,
+ cherokee_buffer_t *buffer,
+ cherokee_socket_status_t *blocking)
{
- ret_t ret;
- size_t written = 0;
- cherokee_connection_t *conn = CONN(post->conn);
+ ret_t ret;
+ size_t written = 0;
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);
-
- conn->polling_aim.fd = sock->socket;
- conn->polling_aim.mode = poll_mode_write;
+ *blocking = socket_writing;
return ret_eagain;
-
default:
return ret_error;
}
@@ -556,11 +538,12 @@ 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_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_socket_status_t *blocking,
+ cherokee_boolean_t *did_IO)
{
ret_t ret;
cherokee_buffer_t *buffer = tmp ? tmp : &post->send.buffer;
@@ -576,6 +559,7 @@ 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;
@@ -594,7 +578,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 (post, sock_out, buffer);
+ ret = do_send_socket (sock_out, buffer, blocking);
switch (ret) {
case ret_ok:
break;
@@ -636,16 +620,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_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_socket_status_t *blocking,
+ cherokee_boolean_t *did_IO)
{
- ret_t ret;
- int r;
- cherokee_connection_t *conn = CONN(post->conn);
- cherokee_buffer_t *buffer = tmp ? tmp : &post->send.buffer;
+ ret_t ret;
+ int r;
+ cherokee_buffer_t *buffer = tmp ? tmp : &post->send.buffer;
switch (post->send.phase) {
@@ -659,6 +643,7 @@ 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;
@@ -680,8 +665,7 @@ cherokee_post_send_to_fd (cherokee_post_t *post,
r = write (fd_out, buffer->buf, buffer->len);
if (r < 0) {
if (errno == EAGAIN) {
- conn->polling_aim.fd = fd_out;
- conn->polling_aim.mode = poll_mode_write;
+ *blocking = socket_writing;
return ret_eagain;
}
View
49 cherokee/post.h
@@ -45,14 +45,13 @@ typedef enum {
} cherokee_post_send_phase_t;
typedef struct {
- 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;
+ 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;
@@ -74,34 +73,36 @@ typedef struct {
CHEROKEE_BEGIN_DECLS
-ret_t cherokee_post_init (cherokee_post_t *post, void *conn);
+ret_t cherokee_post_init (cherokee_post_t *post);
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);
+ret_t cherokee_post_read_header (cherokee_post_t *post, void *conn);
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_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);
+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);
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),
- poll_mode_read);
+ FDPOLL_MODE_READ);
if (ret < ret_ok)
return ret;
}
@@ -1827,25 +1827,21 @@ 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) {
- len = 0;
- cherokee_list_get_len (&THREAD(thread)->active_list, &len);
- active += len;
+ active += THREAD(thread)->active_list_num;
}
- len = 0;
- cherokee_list_get_len (&srv->main_thread->active_list, &len);
- active += len;
+ active += srv->main_thread->active_list_num;
/* 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->closed = true;
+ socket->status = socket_closed;
socket->is_tls = non_TLS;
socket->cryptor = NULL;
@@ -149,7 +149,7 @@ cherokee_socket_clean (cherokee_socket_t *socket)
/* Properties
*/
socket->socket = -1;
- socket->closed = true;
+ socket->status = socket_closed;
/* Client address
*/
@@ -210,7 +210,7 @@ cherokee_socket_close (cherokee_socket_t *socket)
socket->socket, socket->is_tls, (int) ret);
socket->socket = -1;
- socket->closed = true;
+ socket->status = socket_closed;
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->closed = false;
- SOCKET_FD(socket) = fd;
+ socket->status = socket_reading;
+ SOCKET_FD(socket) = fd;
return ret_ok;
}
@@ -698,7 +698,7 @@ cherokee_socket_write (cherokee_socket_t *socket,
#ifdef ENOTCONN
case ENOTCONN:
#endif
- socket->closed = true;
+ socket->status = socket_closed;
case ETIMEDOUT:
case EHOSTUNREACH:
return ret_error;
@@ -718,7 +718,7 @@ cherokee_socket_write (cherokee_socket_t *socket,
case ret_eagain:
return</