Skip to content
This repository
Browse code

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
Antonio Pérez authored February 27, 2012
8  admin/static/css/cherokee-admin.css
@@ -426,8 +426,6 @@ img.icon_chooser_selected {
426 426
     background: #235699;
427 427
     background: -webkit-gradient(linear, left top, left bottom, from(#5e8bc9), to(#235699));
428 428
     background: -moz-linear-gradient(top,  #396aae,  #235699);
429  
-    background: -o-linear-gradient(top,  #396aae,  #235699);
430  
-    background: linear-gradient(top,  #396aae,  #235699);
431 429
     filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#396aae', endColorstr='#235699');
432 430
     -moz-box-shadow: inset 1px 1px 0 #7798c2;
433 431
     -webkit-box-shadow: inset 1px 1px 0 #7798c2;
@@ -440,8 +438,6 @@ img.icon_chooser_selected {
440 438
     background: #24589b;
441 439
     background: -webkit-gradient(linear, left top, left bottom, from(#24589b), to(#24589b));
442 440
     background: -moz-linear-gradient(top,  #24589b,  #24589b);
443  
-    background: -o-linear-gradient(top,  #24589b,  #24589b);
444  
-    background: linear-gradient(top,  #24589b,  #24589b);
445 441
     filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#24589b', endColorstr='#24589b');
446 442
     -moz-box-shadow: inset 1px 1px 0 #24589b;
447 443
     -webkit-box-shadow: inset 1px 1px 0 #24589b;
@@ -598,8 +594,6 @@ img.icon_chooser_selected {
598 594
     background: #2fa42c;
599 595
     background: -webkit-gradient(linear, left top, left bottom, from(#7ac25a), to(#2fa42c));
600 596
     background: -moz-linear-gradient(top,  #7ac25a,  #2fa42c);
601  
-    background: -o-linear-gradient(top,  #7ac25a,  #2fa42c);
602  
-    background: linear-gradient(top,  #7ac25a,  #2fa42c);
603 597
     filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#7ac25a', endColorstr='#2fa42c');
604 598
     -moz-box-shadow: inset 1px 1px 0 rgba(255,255,255,0.4);
605 599
     -webkit-box-shadow: inset 1px 1px 0 rgba(255,255,255,0.4);
@@ -616,8 +610,6 @@ img.icon_chooser_selected {
616 610
     background: #cc0000;
617 611
     background: -webkit-gradient(linear, left top, left bottom, from(#ff8888), to(#cc0000));
618 612
     background: -moz-linear-gradient(top,  #ff8888,  #cc0000);
619  
-    background: -o-linear-gradient(top,  #ff8888,  #cc0000);
620  
-    background: linear-gradient(top,  #ff8888,  #cc0000);
621 613
     filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff8888', endColorstr='#cc0000');
622 614
     -moz-box-shadow: inset 1px 1px 0 rgba(255,255,255,0.4);
623 615
     -webkit-box-shadow: inset 1px 1px 0 rgba(255,255,255,0.4);
2  cherokee/Makefile.am
@@ -1577,8 +1577,6 @@ $(common_rrd_tools) \
1577 1577
 \
1578 1578
 connection.h \
1579 1579
 connection-protected.h \
1580  
-connection-poll.h \
1581  
-connection-poll.c \
1582 1580
 connection.c \
1583 1581
 handler.h \
1584 1582
 handler.c \
25  cherokee/bind.c
@@ -171,12 +171,33 @@ set_socket_opts (int socket)
171 171
 	if (ret != ret_ok)
172 172
 		return ret;
173 173
 
  174
+	/* TCP_MAXSEG:
  175
+	 * The maximum size of a TCP segment is based on the network MTU for des-
  176
+	 * tinations on local networks or on a default MTU of 576 bytes for desti-
  177
+	 * nations on nonlocal networks.  The default behavior can be altered by
  178
+	 * setting the TCP_MAXSEG option to an integer value from 1 to 65,535.
  179
+	 * However, TCP will not use a maximum segment size smaller than 32 or
  180
+	 * larger than the local network MTU.  Setting the TCP_MAXSEG option to a
  181
+	 * value of zero results in default behavior.  The TCP_MAXSEG option can
  182
+	 * only be set prior to calling listen or connect on the socket.  For pas-
  183
+	 * sive connections, the TCP_MAXSEG option value is inherited from the
  184
+	 * listening socket. This option takes an int value, with a range of 0 to
  185
+	 * 65535.
  186
+	 */
  187
+#ifdef TCP_MAXSEG
  188
+	on = 64000;
  189
+	setsockopt (socket, SOL_SOCKET, TCP_MAXSEG, &on, sizeof(on));
  190
+
  191
+	/* Do no check the returned value */
  192
+#endif
  193
+
174 194
 	/* TCP_DEFER_ACCEPT:
175 195
 	 * Allows a listener to be awakened only when data arrives on the socket.
176 196
 	 * Takes an integer value (seconds), this can bound the maximum number of
177  
-	 * attempts TCP will make to complete the connection.
  197
+	 * attempts TCP will make to complete the connection. This option should
  198
+	 * not be used in code intended to be portable.
178 199
 	 *
179  
-	 * Gives clients 5secs to send the first data packet
  200
+	 * Give clients 5s to send first data packet
180 201
 	 */
181 202
 #ifdef TCP_DEFER_ACCEPT
182 203
 	on = 5;
58  cherokee/connection-poll.c
... ...
@@ -1,58 +0,0 @@
1  
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2  
-
3  
-/* Cherokee
4  
- *
5  
- * Authors:
6  
- *      Alvaro Lopez Ortega <alvaro@alobbs.com>
7  
- *
8  
- * Copyright (C) 2001-2011 Alvaro Lopez Ortega
9  
- *
10  
- * This program is free software; you can redistribute it and/or
11  
- * modify it under the terms of version 2 of the GNU General Public
12  
- * License as published by the Free Software Foundation.
13  
- *
14  
- * This program is distributed in the hope that it will be useful,
15  
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  
- * GNU General Public License for more details.
18  
- *
19  
- * You should have received a copy of the GNU General Public License
20  
- * along with this program; if not, write to the Free Software
21  
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  
- * 02110-1301, USA.
23  
- */
24  
-
25  
-#include "common-internal.h"
26  
-#include "connection-poll.h"
27  
-
28  
-ret_t
29  
-cherokee_connection_poll_init (cherokee_connection_pool_t *conn_poll)
30  
-{
31  
-	conn_poll->fd   = -1;
32  
-	conn_poll->mode = poll_mode_nothing;
33  
-
34  
-	return ret_ok;
35  
-}
36  
-
37  
-ret_t
38  
-cherokee_connection_poll_mrproper (cherokee_connection_pool_t *conn_poll)
39  
-{
40  
-	UNUSED (conn_poll);
41  
-	return ret_ok;
42  
-}
43  
-
44  
-ret_t
45  
-cherokee_connection_poll_clean (cherokee_connection_pool_t *conn_poll)
46  
-{
47  
-	conn_poll->fd   = -1;
48  
-	conn_poll->mode = poll_mode_nothing;
49  
-
50  
-	return ret_ok;
51  
-}
52  
-
53  
-int
54  
-cherokee_connection_poll_is_set (cherokee_connection_pool_t *conn_poll)
55  
-{
56  
-	return ((conn_poll->fd != -1) ||
57  
-		(conn_poll->mode != poll_mode_nothing));
58  
-}
47  cherokee/connection-poll.h
... ...
@@ -1,47 +0,0 @@
1  
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2  
-
3  
-/* Cherokee
4  
- *
5  
- * Authors:
6  
- *      Alvaro Lopez Ortega <alvaro@alobbs.com>
7  
- *
8  
- * Copyright (C) 2001-2011 Alvaro Lopez Ortega
9  
- *
10  
- * This program is free software; you can redistribute it and/or
11  
- * modify it under the terms of version 2 of the GNU General Public
12  
- * License as published by the Free Software Foundation.
13  
- *
14  
- * This program is distributed in the hope that it will be useful,
15  
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  
- * GNU General Public License for more details.
18  
- *
19  
- * You should have received a copy of the GNU General Public License
20  
- * along with this program; if not, write to the Free Software
21  
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  
- * 02110-1301, USA.
23  
- */
24  
-
25  
-#if !defined (CHEROKEE_INSIDE_CHEROKEE_H) && !defined (CHEROKEE_COMPILATION)
26  
-# error "Only <cherokee/cherokee.h> can be included directly, this file may disappear or change contents."
27  
-#endif
28  
-
29  
-#ifndef CHEROKEE_CONNECTION_POLL_H
30  
-#define CHEROKEE_CONNECTION_POLL_H
31  
-
32  
-#include "common.h"
33  
-#include "fdpoll.h"
34  
-
35  
-
36  
-typedef struct {
37  
-	cherokee_poll_mode_t mode;
38  
-	int                  fd;
39  
-} cherokee_connection_pool_t;
40  
-
41  
-
42  
-ret_t cherokee_connection_poll_init     (cherokee_connection_pool_t *conn_poll);
43  
-ret_t cherokee_connection_poll_clean    (cherokee_connection_pool_t *conn_poll);
44  
-ret_t cherokee_connection_poll_mrproper (cherokee_connection_pool_t *conn_poll);
45  
-int   cherokee_connection_poll_is_set   (cherokee_connection_pool_t *conn_poll);
46  
-
47  
-#endif /* CHEROKEE_CONNECTION_POLL_H */
14  cherokee/connection-protected.h
@@ -68,7 +68,6 @@
68 68
 #include "bind.h"
69 69
 #include "bogotime.h"
70 70
 #include "config_entry.h"
71  
-#include "connection-poll.h"
72 71
 
73 72
 typedef enum {
74 73
 	phase_nothing,
@@ -90,9 +89,10 @@ typedef enum {
90 89
 #define conn_op_root_index        (1 << 1)
91 90
 #define conn_op_tcp_cork          (1 << 2)
92 91
 #define conn_op_document_root     (1 << 3)
93  
-#define conn_op_cant_encoder      (1 << 4)
94  
-#define conn_op_got_eof           (1 << 5)
95  
-#define conn_op_chunked_formatted (1 << 6)
  92
+#define conn_op_was_polling       (1 << 4)
  93
+#define conn_op_cant_encoder      (1 << 5)
  94
+#define conn_op_got_eof           (1 << 6)
  95
+#define conn_op_chunked_formatted (1 << 7)
96 96
 
97 97
 typedef cuint_t cherokee_connection_options_t;
98 98
 
@@ -192,7 +192,9 @@ struct cherokee_connection {
192 192
 
193 193
 	/* Polling
194 194
 	 */
195  
-	cherokee_connection_pool_t    polling_aim;
  195
+	int                           polling_fd;
  196
+	cherokee_socket_status_t      polling_mode;
  197
+	cherokee_boolean_t            polling_multiple;
196 198
 
197 199
 	off_t                         range_start;
198 200
 	off_t                         range_end;
@@ -252,7 +254,7 @@ struct cherokee_connection {
252 254
  */
253 255
 ret_t cherokee_connection_new                    (cherokee_connection_t **conn);
254 256
 ret_t cherokee_connection_free                   (cherokee_connection_t  *conn);
255  
-ret_t cherokee_connection_clean                  (cherokee_connection_t  *conn, cherokee_boolean_t reuse);
  257
+ret_t cherokee_connection_clean                  (cherokee_connection_t  *conn);
256 258
 ret_t cherokee_connection_clean_close            (cherokee_connection_t  *conn);
257 259
 
258 260
 /* Close
133  cherokee/connection.c
@@ -120,6 +120,9 @@ cherokee_connection_new  (cherokee_connection_t **conn)
120 120
 	n->timeout                   = -1;
121 121
 	n->timeout_lapse             = -1;
122 122
 	n->timeout_header            = NULL;
  123
+	n->polling_fd                = -1;
  124
+	n->polling_multiple          = false;
  125
+	n->polling_mode              = FDPOLL_MODE_NONE;
123 126
 	n->expiration                = cherokee_expiration_none;
124 127
 	n->expiration_time           = 0;
125 128
 	n->expiration_prop           = cherokee_expiration_prop_none;
@@ -155,8 +158,7 @@ cherokee_connection_new  (cherokee_connection_t **conn)
155 158
 
156 159
 	cherokee_socket_init (&n->socket);
157 160
 	cherokee_header_init (&n->header, header_type_request);
158  
-	cherokee_post_init (&n->post, n);
159  
-	cherokee_connection_poll_init (&n->polling_aim);
  161
+	cherokee_post_init (&n->post);
160 162
 
161 163
 	memset (n->regex_ovector, 0, OVECTOR_LEN * sizeof(int));
162 164
 	n->regex_ovecsize = 0;
@@ -230,11 +232,11 @@ cherokee_connection_free (cherokee_connection_t  *conn)
230 232
 		conn->arguments = NULL;
231 233
 	}
232 234
 
233  
-
234  
-	if (conn->polling_aim.fd != -1) {
235  
-                cherokee_fd_close (conn->polling_aim.fd);
236  
-	}
237  
-	cherokee_connection_poll_mrproper (&conn->polling_aim);
  235
+        if (conn->polling_fd != -1) {
  236
+                cherokee_fd_close (conn->polling_fd);
  237
+                conn->polling_fd   = -1;
  238
+		conn->polling_mode = FDPOLL_MODE_NONE;
  239
+        }
238 240
 
239 241
 	free (conn);
240 242
 	return ret_ok;
@@ -242,8 +244,7 @@ cherokee_connection_free (cherokee_connection_t  *conn)
242 244
 
243 245
 
244 246
 ret_t
245  
-cherokee_connection_clean (cherokee_connection_t *conn,
246  
-			   cherokee_boolean_t     reuse)
  247
+cherokee_connection_clean (cherokee_connection_t *conn)
247 248
 {
248 249
 	size_t             crlf_len;
249 250
 	uint32_t           header_len;
@@ -288,10 +289,10 @@ cherokee_connection_clean (cherokee_connection_t *conn,
288 289
 	conn->encoder_new_func = NULL;
289 290
 	conn->encoder_props    = NULL;
290 291
 
291  
-	if (conn->polling_aim.fd != -1) {
292  
-                cherokee_fd_close (conn->polling_aim.fd);
  292
+	if (conn->polling_fd != -1) {
  293
+		cherokee_fd_close (conn->polling_fd);
  294
+		conn->polling_fd = -1;
293 295
 	}
294  
-	cherokee_connection_poll_clean (&conn->polling_aim);
295 296
 
296 297
 	if (conn->validator != NULL) {
297 298
 		cherokee_validator_free (conn->validator);
@@ -314,6 +315,8 @@ cherokee_connection_clean (cherokee_connection_t *conn,
314 315
 	conn->rx_partial           = 0;
315 316
 	conn->tx_partial           = 0;
316 317
 	conn->traffic_next         = 0;
  318
+	conn->polling_multiple     = false;
  319
+	conn->polling_mode         = FDPOLL_MODE_NONE;
317 320
 	conn->expiration           = cherokee_expiration_none;
318 321
 	conn->expiration_time      = 0;
319 322
 	conn->expiration_prop      = cherokee_expiration_prop_none;
@@ -330,8 +333,6 @@ cherokee_connection_clean (cherokee_connection_t *conn,
330 333
 	memset (conn->regex_host_ovector, 0, OVECTOR_LEN * sizeof(int));
331 334
 	conn->regex_host_ovecsize = 0;
332 335
 
333  
-	cherokee_connection_poll_clean (&conn->polling_aim);
334  
-
335 336
 	cherokee_post_clean (&conn->post);
336 337
 	cherokee_buffer_mrproper (&conn->encoder_buffer);
337 338
 
@@ -372,24 +373,27 @@ cherokee_connection_clean (cherokee_connection_t *conn,
372 373
 	cherokee_buffer_clean (&conn->buffer);
373 374
 	cherokee_buffer_clean (&conn->header_buffer);
374 375
 
375  
-	if (reuse) {
376  
-		/* Skip trailing CRLF (which may be sent by some HTTP clients)
377  
-		 * only if the number of CRLFs is within the predefine count
378  
-		 * limit otherwise ignore trailing CRLFs so that they will be
379  
-		 * handled in next request.  This may avoid a subsequent real
380  
-		 * move_to_begin of the contents left in the buffer.
381  
-		 */
382  
-		crlf_len = cherokee_buffer_cnt_spn (&conn->incoming_header, header_len, CRLF);
383  
-		header_len += (crlf_len <= MAX_HEADER_CRLF) ? crlf_len : 0;
  376
+	/* Skip trailing CRLF (which may be sent by some HTTP clients)
  377
+	 * only if the number of CRLFs is within the predefine count
  378
+	 * limit otherwise ignore trailing CRLFs so that they will be
  379
+	 * handled in next request.  This may avoid a subsequent real
  380
+	 * move_to_begin of the contents left in the buffer.
  381
+	 */
  382
+	crlf_len = cherokee_buffer_cnt_spn (&conn->incoming_header, header_len, CRLF);
  383
+	header_len += (crlf_len <= MAX_HEADER_CRLF) ? crlf_len : 0;
384 384
 
385  
-		cherokee_buffer_move_to_begin (&conn->incoming_header, header_len);
  385
+	cherokee_buffer_move_to_begin (&conn->incoming_header, header_len);
386 386
 
387  
-		TRACE (ENTRIES, "conn %p, %s headers\n", conn,
388  
-		       !cherokee_buffer_is_empty (&conn->incoming_header) ? "has" : "doesn't have");
389  
-	} else {
390  
-		cherokee_buffer_clean (&conn->incoming_header);
  387
+	/* If the connection has incoming headers to be processed,
  388
+	 * then increment the pending counter from the thread
  389
+	 */
  390
+	if (! cherokee_buffer_is_empty (&conn->incoming_header)) {
  391
+		CONN_THREAD(conn)->pending_conns_num++;
391 392
 	}
392 393
 
  394
+	TRACE (ENTRIES, "conn %p, has headers %d\n", conn,
  395
+	       !cherokee_buffer_is_empty (&conn->incoming_header));
  396
+
393 397
 	return ret_ok;
394 398
 }
395 399
 
@@ -409,7 +413,7 @@ cherokee_connection_clean_close (cherokee_connection_t *conn)
409 413
 
410 414
 	/* Clean the connection object
411 415
 	 */
412  
-	cherokee_connection_clean (conn, false);
  416
+	cherokee_connection_clean (conn);
413 417
 	return ret_ok;
414 418
 }
415 419
 
@@ -1053,12 +1057,8 @@ cherokee_connection_send_header_and_mmaped (cherokee_connection_t *conn)
1053 1057
 		if (unlikely (ret != ret_ok) ) {
1054 1058
 			switch (ret) {
1055 1059
 			case ret_eof:
1056  
-				return ret_eof;
1057  
-
1058 1060
 			case ret_eagain:
1059  
-				conn->polling_aim.fd   = conn->socket.socket;
1060  
-				conn->polling_aim.mode = poll_mode_write;
1061  
-				return ret_eagain;
  1061
+				return ret;
1062 1062
 
1063 1063
 			case ret_error:
1064 1064
 				conn->keepalive = 0;
@@ -1095,12 +1095,8 @@ cherokee_connection_send_header_and_mmaped (cherokee_connection_t *conn)
1095 1095
 		switch (ret) {
1096 1096
 
1097 1097
 		case ret_eof:
1098  
-			return ret_eof;
1099  
-
1100 1098
 		case ret_eagain:
1101  
-			conn->polling_aim.fd   = conn->socket.socket;
1102  
-			conn->polling_aim.mode = poll_mode_write;
1103  
-			return ret_eagain;
  1099
+			return ret;
1104 1100
 
1105 1101
 		case ret_error:
1106 1102
 			conn->keepalive = 0;
@@ -1192,15 +1188,15 @@ cherokee_connection_recv (cherokee_connection_t *conn,
1192 1188
 		return ret;
1193 1189
 
1194 1190
 	case ret_eagain:
  1191
+		if (cherokee_socket_pending_read (&conn->socket)) {
  1192
+			CONN_THREAD(conn)->pending_read_num += 1;
  1193
+		}
  1194
+
1195 1195
 		if (cnt_read > 0) {
1196 1196
 			cherokee_connection_rx_add (conn, cnt_read);
1197 1197
 			*len = cnt_read;
1198 1198
 			return ret_ok;
1199 1199
 		}
1200  
-
1201  
-		conn->polling_aim.fd   = conn->socket.socket;
1202  
-		conn->polling_aim.mode = poll_mode_read;
1203  
-
1204 1200
 		return ret_eagain;
1205 1201
 
1206 1202
 	default:
@@ -1258,18 +1254,7 @@ cherokee_connection_send_header (cherokee_connection_t *conn)
1258 1254
 	/* Send the buffer content
1259 1255
 	 */
1260 1256
 	ret = cherokee_socket_bufwrite (&conn->socket, &conn->buffer, &sent);
1261  
-	switch (ret) {
1262  
-	case ret_ok:
1263  
-		break;
1264  
-
1265  
-	case ret_eagain:
1266  
-		conn->polling_aim.fd   = conn->socket.socket;
1267  
-		conn->polling_aim.mode = poll_mode_write;
1268  
-		return ret_eagain;
1269  
-
1270  
-	default:
1271  
-		return ret;
1272  
-	}
  1257
+	if (unlikely(ret != ret_ok)) return ret;
1273 1258
 
1274 1259
 	/* Add to the connection traffic counter
1275 1260
 	 */
@@ -1355,12 +1340,8 @@ cherokee_connection_send (cherokee_connection_t *conn)
1355 1340
 			break;
1356 1341
 
1357 1342
 		case ret_eof:
1358  
-			return ret_eof;
1359  
-
1360 1343
 		case ret_eagain:
1361  
-			conn->polling_aim.fd   = conn->socket.socket;
1362  
-			conn->polling_aim.mode = poll_mode_write;
1363  
-			return ret_eagain;
  1344
+			return ret;
1364 1345
 
1365 1346
 		case ret_error:
1366 1347
 			conn->keepalive = 0;
@@ -1398,18 +1379,8 @@ cherokee_connection_send (cherokee_connection_t *conn)
1398 1379
 	}
1399 1380
 
1400 1381
 	ret = cherokee_socket_write (&conn->socket, conn->buffer.buf, to_send, &sent);
1401  
-	switch (ret) {
1402  
-	case ret_ok:
1403  
-		break;
1404  
-
1405  
-	case ret_eagain:
1406  
-		conn->polling_aim.fd   = conn->socket.socket;
1407  
-		conn->polling_aim.mode = poll_mode_write;
1408  
-		return ret_eagain;
1409  
-
1410  
-	default:
  1382
+	if (unlikely(ret != ret_ok))
1411 1383
 		return ret;
1412  
-	}
1413 1384
 
1414 1385
 	/* Drop out the sent info
1415 1386
 	 */
@@ -1552,17 +1523,12 @@ cherokee_connection_linger_read (cherokee_connection_t *conn)
1552 1523
 	cherokee_thread_t *thread   = CONN_THREAD(conn);
1553 1524
 	cherokee_buffer_t *tmp1     = THREAD_TMP_BUF1(thread);
1554 1525
 
1555  
-	TRACE(ENTRIES",linger", "Linger read, socket %s closed\n", conn->socket.closed ? "is" : "isn't");
  1526
+	TRACE(ENTRIES",linger", "Linger read, socket status %d\n", conn->socket.status);
1556 1527
 
1557 1528
 	while (true) {
1558 1529
 		/* Read from the socket to nowhere
1559 1530
 		 */
1560  
-		ret = cherokee_socket_read (&conn->socket, tmp1->buf, tmp1->size - 1, &cnt_read);
1561  
-
1562  
-		if (cnt_read > 0) {
1563  
-			cherokee_buffer_clean (tmp1);
1564  
-		}
1565  
-
  1531
+		ret = cherokee_socket_read (&conn->socket, tmp1->buf, tmp1->size, &cnt_read);
1566 1532
 		switch (ret) {
1567 1533
 		case ret_eof:
1568 1534
 			TRACE (ENTRIES",linger", "%s\n", "EOF");
@@ -1572,17 +1538,12 @@ cherokee_connection_linger_read (cherokee_connection_t *conn)
1572 1538
 			return ret_error;
1573 1539
 		case ret_eagain:
1574 1540
 			TRACE (ENTRIES",linger", "read %u, eagain\n", cnt_read);
1575  
-
1576  
-			conn->polling_aim.fd   = conn->socket.socket;
1577  
-			conn->polling_aim.mode = poll_mode_read;
1578 1541
 			return ret_eagain;
1579 1542
 		case ret_ok:
1580 1543
 			TRACE (ENTRIES",linger", "%u bytes tossed away\n", cnt_read);
1581  
-
1582 1544
 			retries--;
1583  
-			if ((cnt_read >= tmp1->size - 2) && (retries > 0))
  1545
+			if (cnt_read == tmp1->size && retries > 0)
1584 1546
 				continue;
1585  
-
1586 1547
 			return ret_eof;
1587 1548
 		default:
1588 1549
 			RET_UNKNOWN(ret);
@@ -2215,7 +2176,7 @@ cherokee_connection_get_request (cherokee_connection_t *conn)
2215 2176
 	 */
2216 2177
 	if (read_post)
2217 2178
 	{
2218  
-		ret = cherokee_post_read_header (&conn->post);
  2179
+		ret = cherokee_post_read_header (&conn->post, conn);
2219 2180
 		if (unlikely (ret != ret_ok)) {
2220 2181
 			return ret;
2221 2182
 		}
@@ -2897,6 +2858,8 @@ cherokee_connection_print (cherokee_connection_t *conn)
2897 2858
 		print_add (" tcp_cork");
2898 2859
 	if (conn->options & conn_op_document_root)
2899 2860
 		print_add (" document_root");
  2861
+	if (conn->options & conn_op_was_polling)
  2862
+		print_add (" was_polling");
2900 2863
 	if (conn->options & conn_op_cant_encoder)
2901 2864
 		print_add (" cant_encoder");
2902 2865
 	if (conn->options & conn_op_got_eof)
2  cherokee/connection_info.c
@@ -186,7 +186,7 @@ cherokee_connection_info_list_thread (cherokee_list_t    *list,
186 186
 
187 187
 	/* Does it has active connections?
188 188
 	 */
189  
-	if (cherokee_list_empty (&thread->active_list))
  189
+	if (thread->active_list_num <= 0)
190 190
 		return ret_not_found;
191 191
 
192 192
 	/* If it tries to adquire the thread ownership of the thread
6  cherokee/downloader_async.c
@@ -93,7 +93,7 @@ cherokee_downloader_async_connect (cherokee_downloader_async_t *adownloader)
93 93
 	ret = cherokee_fd_set_nonblocking (down->socket.socket, true);
94 94
 	if (ret != ret_ok) return ret;
95 95
 
96  
-	ret = cherokee_fdpoll_add (fdpoll, down->socket.socket, poll_mode_write);
  96
+	ret = cherokee_fdpoll_add (fdpoll, down->socket.socket, FDPOLL_MODE_WRITE);
97 97
 	if (ret != ret_ok) return ret;
98 98
 
99 99
 	adownloader->fd_added = down->socket.socket;
@@ -123,9 +123,9 @@ cherokee_downloader_async_step (cherokee_downloader_async_t *adownloader)
123 123
 	/* Check whether we are reading or writting
124 124
 	 */
125 125
 	if (down->phase <= downloader_phase_send_post)
126  
-		rw = poll_mode_write;
  126
+		rw = FDPOLL_MODE_WRITE;
127 127
 	else
128  
-		rw = poll_mode_read;
  128
+		rw = FDPOLL_MODE_READ;
129 129
 
130 130
 	TRACE(ENTRIES, "rw = %d\n", rw);
131 131
 
4  cherokee/error_list.py
@@ -904,6 +904,10 @@
904 904
 
905 905
 # cherokee/thread.c
906 906
 #
  907
+e('THREAD_RM_FD_POLL',
  908
+  title = "Could not remove fd(%d) from fdpoll",
  909
+  desc  = CODING_BUG)
  910
+
907 911
 e('THREAD_HANDLER_RET',
908 912
   title = "Unknown ret %d from handler %s",
909 913
   desc  = CODING_BUG)
79  cherokee/fdpoll-epoll.c
@@ -80,7 +80,7 @@ _free (cherokee_fdpoll_epoll_t *fdp)
80 80
 
81 81
 
82 82
 static ret_t
83  
-_add (cherokee_fdpoll_epoll_t *fdp, int fd, int mode_rw)
  83
+_add (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
84 84
 {
85 85
 	struct epoll_event ev;
86 86
 
@@ -94,20 +94,16 @@ _add (cherokee_fdpoll_epoll_t *fdp, int fd, int mode_rw)
94 94
 	/* Add the new descriptor
95 95
 	 */
96 96
 	ev.data.u64 = 0;
97  
-	ev.data.fd  = fd;
98  
-	ev.events   = 0;
99  
-
100  
-	/* Set mode
101  
-	 */
102  
-	if (mode_rw & poll_mode_read) {
103  
-		ev.events |= (EPOLLIN | EPOLLERR | EPOLLHUP);
104  
-	}
105  
-
106  
-	if (mode_rw & poll_mode_write) {
107  
-		ev.events |= (EPOLLOUT | EPOLLERR | EPOLLHUP);
108  
-	}
109  
-
110  
-	if (unlikely (ev.events == 0)) {
  97
+	ev.data.fd = fd;
  98
+	switch (rw) {
  99
+	case FDPOLL_MODE_READ:
  100
+		ev.events = EPOLLIN | EPOLLERR | EPOLLHUP;
  101
+		break;
  102
+	case FDPOLL_MODE_WRITE:
  103
+		ev.events = EPOLLOUT | EPOLLERR | EPOLLHUP;
  104
+		break;
  105
+	default:
  106
+		ev.events = 0;
111 107
 		SHOULDNT_HAPPEN;
112 108
 		return ret_error;
113 109
 	}
@@ -128,6 +124,10 @@ _del (cherokee_fdpoll_epoll_t *fdp, int fd)
128 124
 {
129 125
 	struct epoll_event ev;
130 126
 
  127
+	ev.events   = 0;
  128
+	ev.data.u64 = 0;  /* <- I just wanna be sure there aren't */
  129
+	ev.data.fd  = fd; /* <- 4 bytes uninitialized */
  130
+
131 131
 	/* Check the fd limit
132 132
 	 */
133 133
 	if (unlikely (cherokee_fdpoll_is_empty (FDPOLL(fdp)))) {
@@ -147,7 +147,7 @@ _del (cherokee_fdpoll_epoll_t *fdp, int fd)
147 147
 
148 148
 
149 149
 static int
150  
-_check (cherokee_fdpoll_epoll_t *fdp, int fd, int rw_mode)
  150
+_check (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
151 151
 {
152 152
 	int      fdidx;
153 153
 	uint32_t events;
@@ -181,19 +181,14 @@ _check (cherokee_fdpoll_epoll_t *fdp, int fd, int rw_mode)
181 181
 	 */
182 182
 	events = fdp->ep_events[fdidx].events;
183 183
 
184  
-	if ((rw_mode & poll_mode_read) && (events & EPOLLIN)) {
185  
-		return 1;
186  
-	}
187  
-
188  
-	if ((rw_mode & poll_mode_write) && (events & EPOLLOUT)) {
189  
-		return 1;
190  
-	}
191  
-
192  
-	if (events & (EPOLLERR | EPOLLHUP)) {
193  
-		return 1;
  184
+	switch (rw) {
  185
+	case FDPOLL_MODE_READ:
  186
+		return events & (EPOLLIN  | EPOLLERR | EPOLLHUP);
  187
+	case FDPOLL_MODE_WRITE:
  188
+		return events & (EPOLLOUT | EPOLLERR | EPOLLHUP);
  189
+	default:
  190
+		return -1;
194 191
 	}
195  
-
196  
-	return -1;
197 192
 }
198 193
 
199 194
 
@@ -212,36 +207,30 @@ _reset (cherokee_fdpoll_epoll_t *fdp, int fd)
212 207
 
213 208
 
214 209
 static ret_t
215  
-_set_mode (cherokee_fdpoll_epoll_t *fdp, int fd, int rw_mode)
  210
+_set_mode (cherokee_fdpoll_epoll_t *fdp, int fd, int rw)
216 211
 {
217 212
 	struct epoll_event ev;
218 213
 
219 214
 	ev.data.u64 = 0;
220 215
 	ev.data.fd  = fd;
221  
-	ev.events   = 0;
222  
-
223  
-	/* Set mode
224  
-	 */
225  
-	if (rw_mode & poll_mode_read) {
226  
-		ev.events |= (EPOLLIN | EPOLLERR | EPOLLHUP);
227  
-	}
228  
-
229  
-	if (rw_mode & poll_mode_write) {
230  
-		ev.events |= (EPOLLOUT | EPOLLERR | EPOLLHUP);
231  
-	}
232 216
 
233  
-	if (unlikely (ev.events == 0)) {
  217
+	switch (rw) {
  218
+	case FDPOLL_MODE_READ:
  219
+		ev.events = EPOLLIN;
  220
+		break;
  221
+	case FDPOLL_MODE_WRITE:
  222
+		ev.events = EPOLLOUT;
  223
+		break;
  224
+	default:
  225
+		ev.events = 0;
234 226
 		return ret_error;
235 227
 	}
236 228
 
237  
-	/* Apply it
238  
-	 */
239  
-	if (epoll_ctl (fdp->ep_fd, EPOLL_CTL_MOD, fd, &ev) < 0) {
  229
+	if (epoll_ctl(fdp->ep_fd, EPOLL_CTL_MOD, fd, &ev) < 0) {
240 230
 		LOG_ERRNO (errno, cherokee_err_error,
241 231
 			   CHEROKEE_ERROR_FDPOLL_EPOLL_CTL_MOD, fdp->ep_fd, fd);
242 232
 		return ret_error;
243 233
 	}
244  
-
245 234
 	return ret_ok;
246 235
 }
247 236
 
111  cherokee/fdpoll-kqueue.c
@@ -91,15 +91,11 @@ _free (cherokee_fdpoll_kqueue_t *fdp)
91 91
 
92 92
 
93 93
 static ret_t
94  
-_add_change (cherokee_fdpoll_kqueue_t *fdp, int fd, int mode, int change)
  94
+_add_change(cherokee_fdpoll_kqueue_t *fdp, int fd, int rw, int change )
95 95
 {
96 96
 	int            index;
97 97
 	struct kevent *event;
98 98
 
99  
-	/* The 'mode' variable should contain a single mode here. This
100  
-	 * function does not support multiple modes.
101  
-	 */
102  
-
103 99
 	index = fdp->nchanges;
104 100
 	if (unlikely (index >= FDPOLL(fdp)->nfiles)) {
105 101
 		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)
108 104
 
109 105
 	event = &fdp->changelist[index];
110 106
 	event->ident = fd;
111  
-
112  
-	switch (mode) {
113  
-	case poll_mode_read:
  107
+	switch (rw) {
  108
+	case FDPOLL_MODE_READ:
114 109
 		event->filter = EVFILT_READ;
115 110
 		break;
116  
-	case poll_mode_write:
  111
+	case FDPOLL_MODE_WRITE:
117 112
 		event->filter = EVFILT_WRITE;
118 113
 		break;
119 114
 	default:
120  
-		event->filter = 0;
121 115
 		SHOULDNT_HAPPEN;
122  
-	}
  116
+        }
123 117
 
124 118
 	event->flags  = change;
125 119
 	event->fflags = 0;
126 120
 
127  
-	fdp->fdinterest[fd] = mode;
  121
+	fdp->fdinterest[fd] = rw;
128 122
 	fdp->nchanges++;
129 123
 
130 124
 	return ret_ok;
@@ -132,55 +126,30 @@ _add_change (cherokee_fdpoll_kqueue_t *fdp, int fd, int mode, int change)
132 126
 
133 127
 
134 128
 static ret_t
135  
-_add (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw_mode)
  129
+_add (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw)
136 130
 {
137  
-	ret_t ret = ret_not_found;
138  
-
139  
-	if (rw_mode & poll_mode_read) {
140  
-		ret = _add_change (fdp, fd, poll_mode_read, EV_ADD);
141  
-		if (ret != ret_ok)
142  
-			return ret;
143  
-	}
  131
+	int re;
144 132
 
145  
-	if (rw_mode & poll_mode_write) {
146  
-		ret = _add_change (fdp, fd, poll_mode_write, EV_ADD);
147  
-		if (ret != ret_ok)
148  
-			return ret;
149  
-	}
150  
-
151  
-	if (ret == ret_ok) {
  133
+	re = _add_change (fdp, fd, rw, EV_ADD);
  134
+	if (re == ret_ok) {
152 135
 		FDPOLL(fdp)->npollfds++;
153 136
 	}
154 137
 
155  
-	return ret;
  138
+	return re;
156 139
 }
157 140
 
158 141
 
159 142
 static ret_t
160 143
 _del (cherokee_fdpoll_kqueue_t *fdp, int fd)
161 144
 {
162  
-	ret_t              ret      = ret_not_found;
163  
-	int                interest = fdp->fdinterest[fd];
164  
-	cherokee_boolean_t error    = false;
165  
-
166  
-	if (interest & poll_mode_read) {
167  
-		ret = _add_change (fdp, fd, poll_mode_read, EV_DELETE);
168  
-		if (ret != ret_ok)
169  
-			error = true;
170  
-	}
  145
+	int re;
171 146
 
172  
-	if (interest & poll_mode_write) {
173  
-		ret = _add_change (fdp, fd, poll_mode_write, EV_DELETE);
174  
-		if (ret != ret_ok)
175  
-			error |= true;
176  
-	}
177  
-
178  
-	if ((ret == ret_ok) && (! error)) {
  147
+	re = _add_change (fdp, fd, fdp->fdinterest[fd], EV_DELETE);
  148
+	if (re == ret_ok) {
179 149
 		FDPOLL(fdp)->npollfds--;
180 150
 	}
181 151
 
182  
-	fdp->fdinterest[fd] = 0;
183  
-	return ret;
  152
+	return re;
184 153
 }
185 154
 
186 155
 
@@ -214,7 +183,7 @@ _watch (cherokee_fdpoll_kqueue_t *fdp, int timeout_msecs)
214 183
 		LOG_ERRNO (errno, cherokee_err_error, CHEROKEE_ERROR_FDPOLL_KQUEUE);
215 184
 		return 0;
216 185
 
217  
-	} else if (n_events >= 0) {
  186
+	} else if (n_events > 0) {
218 187
 		memset (fdp->fdevents, 0, FDPOLL(fdp)->system_nfiles * sizeof(int));
219 188
 
220 189
 		for (i = 0; i < n_events; ++i) {
@@ -238,7 +207,7 @@ _watch (cherokee_fdpoll_kqueue_t *fdp, int timeout_msecs)
238 207
 }
239 208
 
240 209
 static int
241  
-_check (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw_mode)
  210
+_check (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw)
242 211
 {
243 212
 	uint32_t events;
244 213
 
@@ -254,16 +223,15 @@ _check (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw_mode)
254 223
 		return 1;
255 224
 	}
256 225
 
257  
-	if ((rw_mode & poll_mode_read) &&
258  
-	    (events & KQUEUE_READ_EVENT))
259  
-	{
260  
-		return 1;
261  
-	}
262  
-
263  
-	if ((rw_mode & poll_mode_write) &&
264  
-	    (events & KQUEUE_WRITE_EVENT))
265  
-	{
266  
-		return 1;
  226
+	switch (rw) {
  227
+	case FDPOLL_MODE_READ:
  228
+		events &= KQUEUE_READ_EVENT;
  229
+		break;
  230
+	case FDPOLL_MODE_WRITE:
  231
+		events &= KQUEUE_WRITE_EVENT;
  232
+		break;
  233
+	default:
  234
+		SHOULDNT_HAPPEN;
267 235
 	}
268 236
 
269 237
 	return events;
@@ -281,29 +249,24 @@ _reset (cherokee_fdpoll_kqueue_t *fdp, int fd)
281 249
 
282 250
 
283 251
 static ret_t
284  
-_set_mode (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw_mode)
  252
+_set_mode (cherokee_fdpoll_kqueue_t *fdp, int fd, int rw)
285 253
 {
286  
-	int prev_interest = fdp->fdinterest[fd];
287  
-
288  
-	/* If transitioning from R->W or from W->R disable any active
289  
-	 * event on the fd as we are no longer interested on it.
  254
+	/* If transitioning from r -> w or from w -> r
  255
+	 * disable any active event on the fd as we are
  256
+	 * no longer interested on it.
290 257
 	 */
291  
-
292  
-	/* No longer reading */
293  
-	if ((! (rw_mode & poll_mode_read)) &&
294  
-	    (prev_interest & poll_mode_read))
  258
+	if ((rw == FDPOLL_MODE_WRITE) &&
  259
+	    (fdp->fdinterest[fd] == FDPOLL_MODE_READ))
295 260
 	{
296  
-		_add_change (fdp, fd, poll_mode_read, EV_DELETE);
297  
-	}
  261
+		_add_change (fdp, fd, FDPOLL_MODE_READ, EV_DELETE);
298 262
 
299  
-	/* No longer writing */
300  
-	if ((! (rw_mode & poll_mode_write)) &&
301  
-	    (prev_interest & poll_mode_write))
  263
+	} else if ((rw == FDPOLL_MODE_READ) &&
  264
+		   (fdp->fdinterest[fd] == FDPOLL_MODE_WRITE))
302 265
 	{
303  
-		_add_change (fdp, fd, poll_mode_write, EV_DELETE);
  266
+		_add_change (fdp, fd, FDPOLL_MODE_WRITE, EV_DELETE);
304 267
 	}
305 268
 
306  
-	return _add_change (fdp, fd, rw_mode, EV_ADD);
  269
+	return _add_change (fdp, fd, rw, EV_ADD);
307 270
 }
308 271
 
309 272
 
86  cherokee/fdpoll-poll.c
@@ -32,6 +32,7 @@
32 32
 #define POLL_READ   (POLLIN  | POLL_ERROR)
33 33
 #define POLL_WRITE  (POLLOUT | POLL_ERROR)
34 34
 
  35
+
35 36
 /***********************************************************************/
36 37
 /* poll()                                                              */
37 38
 /*                                                                     */
@@ -67,10 +68,9 @@ _free (cherokee_fdpoll_poll_t *fdp)
67 68
 
68 69
 
69 70
 static ret_t
70  
-_add (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
  71
+_add (cherokee_fdpoll_poll_t *fdp, int fd, int rw)
71 72
 {
72  
-	short              events;
73  
-	cherokee_fdpoll_t *nfd     = FDPOLL(fdp);
  73
+	cherokee_fdpoll_t *nfd = FDPOLL(fdp);
74 74
 
75 75
 	/* Check the fd limit
76 76
 	 */
@@ -79,20 +79,21 @@ _add (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
79 79
 		return ret_error;
80 80
 	}
81 81
 
82  
-	/* Translate mode */
83  
-	events = 0;
84  
-	if (rw_mode & poll_mode_read) {
85  
-		events |= POLLIN;
86  
-	}
87  
-	if (rw_mode & poll_mode_write) {
88  
-		events |= POLLOUT;
89  
-	}
90  
-
91  
-	/* Set values */
92  
-	fdp->pollfds[nfd->npollfds].events  = events;
93 82
 	fdp->pollfds[nfd->npollfds].fd      = fd;
94 83
 	fdp->pollfds[nfd->npollfds].revents = 0;
95 84
 
  85
+	switch (rw) {
  86
+	case FDPOLL_MODE_READ:
  87
+		fdp->pollfds[nfd->npollfds].events = POLLIN;
  88
+		break;
  89
+	case FDPOLL_MODE_WRITE:
  90
+		fdp->pollfds[nfd->npollfds].events = POLLOUT;
  91
+		break;
  92
+	default:
  93
+		SHOULDNT_HAPPEN;
  94
+		return ret_error;
  95
+	}
  96
+
96 97
 	fdp->fdidx[fd] = nfd->npollfds;
97 98
 	nfd->npollfds++;
98 99
 
@@ -101,18 +102,9 @@ _add (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
101 102
 
102 103
 
103 104
 static ret_t
104  
-_set_mode (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
  105
+_set_mode (cherokee_fdpoll_poll_t *fdp, int fd, int rw)
105 106
 {
106  
-	short events = 0;
107  
-
108  
-	if (rw_mode & poll_mode_read) {
109  
-		events |= POLLIN;
110  
-	}
111  
-	if (rw_mode & poll_mode_write) {
112  
-		events |= POLLOUT;
113  
-	}
114  
-
115  
-	fdp->pollfds[fdp->fdidx[fd]].events = events;
  107
+	fdp->pollfds[fdp->fdidx[fd]].events = (rw == FDPOLL_MODE_WRITE ? POLLOUT : POLLIN);
116 108
 	return ret_ok;
117 109
 }
118 110
 
@@ -158,30 +150,25 @@ _del (cherokee_fdpoll_poll_t *fdp, int fd)
158 150
 
159 151
 
160 152
 static int
161  
-_check (cherokee_fdpoll_poll_t *fdp, int fd, int rw_mode)
  153
+_check (cherokee_fdpoll_poll_t *fdp, int fd, int rw)
162 154
 {
163 155
 	int revents;
164  
-	int idx      = fdp->fdidx[fd];
  156
+	int idx = fdp->fdidx[fd];
165 157
 
166 158
 	if (idx < 0 || idx >= FDPOLL(fdp)->nfiles)
167 159
 		return -1;
168 160
 
169 161
 	revents = fdp->pollfds[idx].revents;
170 162
 
171  
-	/* Actual result */
172  
-	if ((rw_mode & poll_mode_read) && (revents & POLLIN)) {
173  
-		return 1;
174  
-	}
175  
-	if ((rw_mode & poll_mode_write) && (revents & POLLOUT)) {
176  
-		return 1;
177  
-	}
178  
-
179  
-	/* Error */
180  
-	if (revents & (POLLERR|POLLHUP|POLLNVAL)) {
181  
-		return 1;
  163
+	switch (rw) {
  164
+		case FDPOLL_MODE_READ:
  165
+			return revents & POLL_READ;
  166
+		case FDPOLL_MODE_WRITE:
  167
+			return revents & POLL_WRITE;
  168
+		default:
  169
+			SHOULDNT_HAPPEN;
  170
+			return -1;
182 171
 	}
183  
-
184  
-	return 0;
185 172
 }
186 173
 
187 174
 
@@ -200,28 +187,11 @@ _reset (cherokee_fdpoll_poll_t *fdp, int fd)
200 187
 static int
201 188
 _watch (cherokee_fdpoll_poll_t *fdp, int timeout_msecs)
202 189
 {
203  
-	int re;
204  
-
205 190
 	if (unlikely (FDPOLL(fdp)->npollfds < 0)) {
206 191
 		SHOULDNT_HAPPEN;
207 192
 	}
208 193
 
209  
-	re = poll (fdp->pollfds, FDPOLL(fdp)->npollfds, timeout_msecs);
210  
-
211  
-#if 0
212  
-	{
213  
-		int                i;
214  
-		cherokee_fdpoll_t *nfd = FDPOLL(fdp);
215  
-
216  
-		printf ("total=%d = ", nfd->npollfds);
217  
-		for (i=0; i < nfd->npollfds; i++) {
218  
-			printf ("fd=%d[%d,%d], ", fdp->pollfds[i].fd, fdp->pollfds[i].events, fdp->pollfds[i].revents);
219  
-		}
220  
-		printf ("\n");
221  
-	}
222  
-#endif
223  
-
224  
-	return re;
  194
+	return poll (fdp->pollfds, FDPOLL(fdp)->npollfds, timeout_msecs);
225 195
 }
226 196
 
227 197
 
85  cherokee/fdpoll-port.c
@@ -32,6 +32,9 @@
32 32
 #include <unistd.h>
33 33
 #include <errno.h>
34 34
 
  35
+#define WRITE ""
  36
+#define READ  NULL
  37
+
35 38
 #define POLL_READ   (POLLIN)
36 39
 #define POLL_WRITE  (POLLOUT)
37 40
 #define POLL_ERROR  (POLLHUP | POLLERR | POLLNVAL)
@@ -67,24 +70,16 @@ typedef struct {
67 70
 
68 71
 
69 72
 static ret_t
70  
-fd_associate (cherokee_fdpoll_port_t *fdp, int fd, void *rw_mode)
  73
+fd_associate( cherokee_fdpoll_port_t *fdp, int fd, void *rw )
71 74
 {
72 75
 	int rc;
73  
-	int events = 0;
74 76
 
75  
-	if (*rw_mode & poll_mode_read) {
76  
-		events |= POLL_READ;
77  
-	}
  77
+	rc = port_associate (fdp->port,                /* port */
  78
+	                     PORT_SOURCE_FD,           /* source */
  79
+	                     fd,                       /* object */
  80
+	                     rw?POLL_WRITE:POLL_READ,  /* events */
  81
+	                     rw);                      /* user data */
78 82
 
79  
-	if (*rw_mode & poll_mode_write) {
80  
-		events |= POLL_WRITE;
81  
-	}
82  
-
83  
-	rc = port_associate (fdp->port,       /* port */
84  
-	                     PORT_SOURCE_FD,  /* source */
85  
-	                     fd,              /* object */
86  
-	                     events,          /* events */
87  
-	                     rw_mode);        /* user data */
88 83
 	if ( rc == -1 ) {
89 84
 		LOG_ERRNO (errno, cherokee_err_error,
90 85
 			   CHEROKEE_ERROR_FDPOLL_PORTS_ASSOCIATE, fd);
@@ -119,12 +114,12 @@ _free (cherokee_fdpoll_port_t *fdp)
119 114
 
120 115
 
121 116
 static ret_t
122  
-_add (cherokee_fdpoll_port_t *fdp, int fd, int rw_mode)
  117
+_add (cherokee_fdpoll_port_t *fdp, int fd, int rw)
123 118
 {
124 119
 	int rc;
125 120
 
126  
-	rc = fd_associate (fdp, fd, rw_mode);
127  
-	if (rc == -1) {
  121
+	rc = fd_associate(fdp, fd, (rw == FDPOLL_MODE_WRITE ? WRITE : READ));
  122
+	if ( rc == -1 ) {
128 123
 		LOG_ERRNO (errno, cherokee_err_error,
129 124
 			   CHEROKEE_ERROR_FDPOLL_PORTS_FD_ASSOCIATE, fd);
130 125
 		return ret_error;
@@ -217,36 +212,27 @@ _watch (cherokee_fdpoll_port_t *fdp, int timeout_msecs)
217 212
 
218 213
 
219 214
 static int
220  
-_check (cherokee_fdpoll_port_t *fdp, int fd, int rw_mode)
  215
+_check (cherokee_fdpoll_port_t *fdp, int fd, int rw)
221 216
 {
222  
-	uint32_t events = 0;
  217
+	uint32_t events;
223 218
 
224 219
 	/* Sanity check: is it a wrong fd?
225 220
 	 */
226  
-	if (unlikely (fd < 0)) {
227  
-		return -1;
228  
-	}
  221
+	if ( fd < 0 ) return -1;
229 222
 
230 223
 	events = fdp->port_activefd[fd];
231  
-	if (events == -1) {
232  
-		return 0;
233  
-	}
234  
-
235  
-	/* Check
236  
-	 */
237  
-	if ((rw_mode & poll_mode_read) && (events & POLL_READ)) {
238  
-		return 1;
  224
+	if ( events == -1 ) return 0;
  225
+
  226
+	switch (rw) {
  227
+	case FDPOLL_MODE_READ:
  228
+		events &= (POLL_READ | POLL_ERROR);
  229
+		break;