Skip to content
This repository
Browse code

Initial set of changes. This patch breaks the infrastructure of the

server core.
  • Loading branch information...
commit 648a4c1151dc2884a93e241cbd98c5fadb3821bb 1 parent 216073a
Alvaro Lopez Ortega authored February 10, 2012
5  cherokee/Makefile.am
@@ -1578,6 +1578,11 @@ $(common_rrd_tools) \
1578 1578
 request-protected.h \
1579 1579
 request.h \
1580 1580
 request.c \
  1581
+protocol.h \
  1582
+protocol_http.h \
  1583
+protocol_http.c \
  1584
+protocol_spdy.h \
  1585
+protocol_spdy.c \
1581 1586
 connection.h \
1582 1587
 connection.c \
1583 1588
 connection-poll.h \
85  cherokee/connection.c
@@ -29,12 +29,27 @@
29 29
 ret_t
30 30
 cherokee_connection_init (cherokee_connection_t *conn)
31 31
 {
32  
-	conn->keepalive = 0;
  32
+	INIT_LIST_HEAD (&conn->list_entry);
  33
+	INIT_LIST_HEAD (&conn->requests);
33 34
 
34 35
 	cherokee_socket_init (&conn->socket);
  36
+	cherokee_protocol_init (&conn->protocol, conn);
35 37
 	cherokee_connection_poll_init (&conn->polling_aim);
36 38
 
37  
-	INIT_LIST_HEAD (&conn->requests);
  39
+	conn->timeout        = -1;
  40
+	conn->timeout_lapse  = -1;
  41
+	conn->timeout_header = NULL;
  42
+	conn->keepalive      = 0;
  43
+
  44
+	conn->rx             = 0;
  45
+	conn->tx             = 0;
  46
+	conn->rx_partial     = 0;
  47
+	conn->tx_partial     = 0;
  48
+	conn->traffic_next   = 0;
  49
+
  50
+	cherokee_buffer_init (&conn->buffer_in);
  51
+	cherokee_buffer_init (&conn->buffer_out);
  52
+
38 53
 	return ret_ok;
39 54
 }
40 55
 
@@ -42,7 +57,7 @@ cherokee_connection_init (cherokee_connection_t *conn)
42 57
 static void
43 58
 reuse_requests (cherokee_connection_t *conn)
44 59
 {
45  
-	cherokee_thread_t *thd      = CONN_THREAD(conn);
  60
+	cherokee_thread_t *thd = CONN_THREAD(conn);
46 61
 	cherokee_list_t   *i, *tmp;
47 62
 
48 63
 	list_for_each_safe (i, tmp, &conn->requests) {
@@ -65,12 +80,17 @@ cherokee_connection_mrproper (cherokee_connection_t *conn)
65 80
 
66 81
 	cherokee_connection_poll_mrproper (&conn->polling_aim);
67 82
 
68  
-	/* Connection socket */
  83
+	/* Properties */
69 84
 	cherokee_socket_mrproper (&conn->socket);
  85
+	cherokee_protocol_mrproper (&conn->protocol);
70 86
 
71 87
 	/* Free requests */
72 88
 	reuse_requests (conn);
73 89
 
  90
+	/* Buffers */
  91
+	cherokee_buffer_mrproper (&conn->buffer_in);
  92
+	cherokee_buffer_mrproper (&conn->buffer_out);
  93
+
74 94
 	return ret_ok;
75 95
 }
76 96
 
@@ -80,6 +100,9 @@ cherokee_connection_clean (cherokee_connection_t *conn)
80 100
 {
81 101
 	cherokee_list_t *i, *tmp;
82 102
 
  103
+	/* Item of a list */
  104
+	INIT_LIST_ENTRY (&conn->list_entry);
  105
+
83 106
 	/* Polling aim */
84 107
 	if (conn->polling_aim.fd != -1) {
85 108
                 cherokee_fd_close (conn->polling_aim.fd);
@@ -87,8 +110,62 @@ cherokee_connection_clean (cherokee_connection_t *conn)
87 110
 
88 111
 	cherokee_connection_poll_clean (&conn->polling_aim);
89 112
 
  113
+	/* Socket */
  114
+	cherokee_socket_close (&conn->socket);
  115
+	cherokee_socket_clean (&conn->socket);
  116
+
90 117
 	/* Free requests */
91 118
 	reuse_requests (conn);
92 119
 
  120
+	/* Timeout */
  121
+	conn->timeout        = -1;
  122
+	conn->timeout_lapse  = -1;
  123
+	conn->timeout_header = NULL;
  124
+
  125
+	/* Traffic */
  126
+	conn->rx             = 0;
  127
+	conn->tx             = 0;
  128
+	conn->rx_partial     = 0;
  129
+	conn->tx_partial     = 0;
  130
+	conn->traffic_next   = 0;
  131
+
  132
+	/* Buffers */
  133
+	cherokee_buffer_clean (&conn->buffer_in);
  134
+	cherokee_buffer_clean (&conn->buffer_out);
  135
+
  136
+	/* Protocol */
  137
+	cherokee_protocol_clean (&conn->protocol);
  138
+
93 139
 	return ret_ok;
94 140
 }
  141
+
  142
+
  143
+void
  144
+cherokee_connection_rx_add (cherokee_connection_t *conn, ssize_t rx)
  145
+{
  146
+	if (likely (rx > 0)) {
  147
+		conn->rx += rx;
  148
+		conn->rx_partial += rx;
  149
+	}
  150
+}
  151
+
  152
+
  153
+void
  154
+cherokee_connection_tx_add (cherokee_connection_t *conn, ssize_t tx)
  155
+{
  156
+	cuint_t to_sleep;
  157
+
  158
+	/* Count it
  159
+	 */
  160
+	conn->tx += tx;
  161
+	conn->tx_partial += tx;
  162
+
  163
+	/* Traffic shaping
  164
+	 */
  165
+	if (conn->limit_rate) {
  166
+		to_sleep = (tx * 1000) / conn->limit_bps;
  167
+
  168
+		/* It's meant to sleep for a while */
  169
+		conn->limit_blocked_until = cherokee_bogonow_msec + to_sleep;
  170
+	}
  171
+}
42  cherokee/connection.h
@@ -29,25 +29,55 @@
29 29
 #include "buffer.h"
30 30
 #include "socket.h"
31 31
 #include "list.h"
  32
+#include "protocol.h"
32 33
 #include "connection-poll.h"
33 34
 
34 35
 CHEROKEE_BEGIN_DECLS
35 36
 
36 37
 typedef struct {
37  
-	cherokee_socket_t          socket;
38  
-	uint32_t                   keepalive;
39  
-	cherokee_connection_pool_t polling_aim;
40  
-	cherokee_list_t            requests;
41  
-} cherokee_connection_t;
  38
+	/* Inherits from list */
  39
+	cherokee_list_t             list_entry;
  40
+
  41
+	/* Pointers */
  42
+	void                       *thread;
  43
+
  44
+	/* Properties */
  45
+	cherokee_socket_t           socket;
  46
+	cherokee_protocol_t         protocol;
  47
+	cherokee_connection_pool_t  polling_aim;
  48
+	cherokee_list_t             requests;
  49
+
  50
+	/* Timeout & Keep-alive */
  51
+	time_t                      timeout;
  52
+	time_t                      timeout_lapse;
  53
+	cherokee_buffer_t          *timeout_header;
  54
+	uint32_t                    keepalive;
42 55
 
43  
-#define CONN(c) ((cherokee_connection_t *)(c))
  56
+	/* Buffers */
  57
+	cherokee_buffer_t           buffer_in;
  58
+	cherokee_buffer_t           buffer_out;
44 59
 
  60
+	/* Traffic */
  61
+	off_t                       rx;                  /* Bytes received */
  62
+	size_t                      rx_partial;          /* RX partial counter */
  63
+	off_t                       tx;                  /* Bytes sent */
  64
+	size_t                      tx_partial;          /* TX partial counter */
  65
+	time_t                      traffic_next;        /* Time to update traffic */
  66
+
  67
+} cherokee_connection_t;
  68
+
  69
+#define CONN(c)        ((cherokee_connection_t *)(c))
  70
+#define CONN_THREAD(c) (CONN(c)->thread)
45 71
 
46 72
 /* Public methods
47 73
  */
48 74
 ret_t cherokee_connection_init     (cherokee_connection_t *conn);
49 75
 ret_t cherokee_connection_mrproper (cherokee_connection_t *conn);
50 76
 
  77
+/* Transfers
  78
+ */
  79
+void cherokee_connection_rx_add    (cherokee_connection_t *conn, ssize_t rx);
  80
+void cherokee_connection_tx_add    (cherokee_connection_t *conn, ssize_t tx);
51 81
 
52 82
 CHEROKEE_END_DECLS
53 83
 
90  cherokee/protocol.c
... ...
@@ -0,0 +1,90 @@
  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 "protocol.h"
  27
+#include "connection.h"
  28
+
  29
+ret_t
  30
+cherokee_protocol_init  (cherokee_protocol_t *proto, void *cnt)
  31
+{
  32
+	cherokee_connection_t *conn = CONN(cnt);
  33
+
  34
+	PROTOCOL_BASE(proto)->conn       = cnt;
  35
+	PROTOCOL_BASE(proto)->type       = proto_unset;
  36
+	PROTOCOL_BASE(proto)->buffer_in  = conn->buffer_in;
  37
+	PROTOCOL_BASE(proto)->buffer_out = conn->buffer_out;
  38
+
  39
+	return ret_ok;
  40
+}
  41
+
  42
+
  43
+ret_t
  44
+cherokee_protocol_clean (cherokee_protocol_t *proto)
  45
+{
  46
+	PROTOCOL_BASE(proto)->type       = proto_unset;
  47
+	PROTOCOL_BASE(proto)->conn       = NULL;
  48
+	PROTOCOL_BASE(proto)->buffer_in  = NULL;
  49
+	PROTOCOL_BASE(proto)->buffer_out = NULL;
  50
+
  51
+	return ret_ok;
  52
+}
  53
+
  54
+
  55
+ret_t
  56
+cherokee_protocol_mrproper (cherokee_protocol_t *proto)
  57
+{
  58
+	cherokee_protocol_clean (proto);
  59
+	return ret_ok;
  60
+}
  61
+
  62
+
  63
+ret_t
  64
+cherokee_protocol_set (cherokee_protocol_t      *proto,
  65
+		       cherokee_protocol_type_t  type)
  66
+{
  67
+	TRACE (ENTRIES, "Setting protocol: %s\n",
  68
+	       type == proto_http ? "HTTP" :
  69
+	       type == proto_spdy ? "SPDY" : "????");
  70
+
  71
+	PROTOCOL_BASE(proto)->type = type;
  72
+	return ret_ok;
  73
+}
  74
+
  75
+
  76
+ret_t
  77
+cherokee_protocol_dispatch (cherokee_protocol_t *proto)
  78
+{
  79
+	switch (PROTOCOL_BASE(proto)->type) {
  80
+	case proto_http:
  81
+		return cherokee_protocol_http_dispatch (proto);
  82
+	case http_spdy:
  83
+		return cherokee_protocol_spdy_dispatch (proto);
  84
+	default:
  85
+		break;
  86
+	}
  87
+
  88
+	SHOULDNT_HAPPEN;
  89
+	return ret_error;
  90
+}
84  cherokee/protocol.h
... ...
@@ -0,0 +1,84 @@
  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
+#ifndef CHEROKEE_PROTOCOL_H
  26
+#define CHEROKEE_PROTOCOL_H
  27
+
  28
+#include "buffer.h"
  29
+#include "list.h"
  30
+
  31
+CHEROKEE_BEGIN_DECLS
  32
+
  33
+/* Protocol types */
  34
+typedef enum {
  35
+	proto_unset,
  36
+	proto_http,
  37
+	proto_spdy,
  38
+} cherokee_protocol_type_t;
  39
+
  40
+/* Base class */
  41
+typedef struct {
  42
+	cherokee_protocol_type_t  type;
  43
+	void                     *conn;
  44
+	cherokee_buffer_t        *buffer_in;
  45
+	cherokee_buffer_t        *buffer_out;
  46
+} cherokee_protocol_base_t;
  47
+
  48
+/* HTTP class
  49
+ */
  50
+typedef struct {
  51
+	cherokee_protocol_base_t base;
  52
+	int                      http;
  53
+} cherokee_protocol_http_t;
  54
+
  55
+/* SPDY class
  56
+ */
  57
+typedef struct {
  58
+	cherokee_protocol_base_t base;
  59
+	int                      http;
  60
+} cherokee_protocol_spdy_t;
  61
+
  62
+/* Union
  63
+ */
  64
+typedef union {
  65
+	cherokee_protocol_http_t http;
  66
+	cherokee_protocol_spdy_t spdy;
  67
+} cherokee_protocol_t;
  68
+
  69
+#define PROTOCOL(p)      ((cherokee_protocol_t *)(p))
  70
+#define PROTOCOL_BASE(p) ((cherokee_protocol_base_t *)(p))
  71
+#define PROTOCOL_HTTP(p) ((cherokee_protocol_http_t *)(p))
  72
+#define PROTOCOL_SPDY(p) ((cherokee_protocol_spdy_t *)(p))
  73
+
  74
+/* Methods */
  75
+ret_t cherokee_protocol_init     (cherokee_protocol_t *proto, void *conn);
  76
+ret_t cherokee_protocol_clean    (cherokee_protocol_t *proto);
  77
+ret_t cherokee_protocol_mrproper (cherokee_protocol_t *proto);
  78
+
  79
+ret_t cherokee_protocol_set      (cherokee_protocol_t *proto, cherokee_protocol_type_t type);
  80
+ret_t cherokee_protocol_dispatch (cherokee_protocol_t *proto);
  81
+
  82
+CHEROKEE_END_DECLS
  83
+
  84
+#endif /* CHEROKEE_PROTOCOL_H */
113  cherokee/protocol_http.c
... ...
@@ -0,0 +1,113 @@
  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 "protocol_http.h"
  27
+
  28
+ret_t
  29
+cherokee_protocol_http_dispatch (cherokee_protocol_t *proto)
  30
+{
  31
+	size_t                 bytes  = 0;
  32
+	cherokee_connection_t *conn   = CONN (PROTOCOL_BASE(proto)->conn);
  33
+	cherokee_fdpoll_t     *fdpoll = CONN_THREAD(conn)->fdpoll;
  34
+	cherokee_connection_t *sock   = SOCKET (&conn->socket);
  35
+	cherokee_poll_mode_t   mode   = poll_mode_nothing;
  36
+	cherokee_poll_mode_t   mode_s = poll_mode_nothing;
  37
+
  38
+	/* Figure out the mode
  39
+	 */
  40
+	if (! cherokee_buffer_is_empty (conn->buffer_out)) {
  41
+		mode |= poll_mode_write;
  42
+	}
  43
+
  44
+	mode_s = cherokee_fdpoll_check (fdpoll, conn->socket.socket);
  45
+	if (mode_s & poll_mode_read) {
  46
+		mode |= poll_mode_read;
  47
+	}
  48
+
  49
+	/* Send
  50
+	 */
  51
+	if (mode & poll_mode_write) {
  52
+		/* Punch buffer in the socket */
  53
+		ret = cherokee_socket_bufwrite (sock, conn->buffer_out, &bytes);
  54
+
  55
+		switch (ret) {
  56
+		case ret_ok:
  57
+			break;
  58
+
  59
+		case ret_eagain:
  60
+			conn->polling_aim.fd   = conn->socket.socket;
  61
+			conn->polling_aim.mode = poll_mode_write;
  62
+			goto receive;
  63
+
  64
+		default:
  65
+			return ret;
  66
+		}
  67
+
  68
+		/* Skip the chunk already sent */
  69
+		cherokee_buffer_move_to_begin (conn->buffer_out, bytes);
  70
+	}
  71
+
  72
+	/* Receive */
  73
+receive:
  74
+	if (mode & poll_mode_read) {
  75
+		bytes = 0;
  76
+
  77
+		ret = cherokee_socket_bufread (sock, conn->buffer_in, to_read, &bytes);
  78
+		switch (ret) {
  79
+		case ret_ok:
  80
+			cherokee_connection_rx_add (conn, cnt_read);
  81
+			*len = cnt_read;
  82
+			return ret_ok;
  83
+
  84
+	case ret_eof:
  85
+	case ret_error:
  86
+		return ret;
  87
+
  88
+	case ret_eagain:
  89
+		if (cnt_read > 0) {
  90
+			cherokee_connection_rx_add (conn, cnt_read);
  91
+			*len = cnt_read;
  92
+			return ret_ok;
  93
+		}
  94
+
  95
+		conn->polling_aim.fd   = conn->socket.socket;
  96
+		conn->polling_aim.mode = poll_mode_read;
  97
+
  98
+		return ret_eagain;
  99
+
  100
+	default:
  101
+		RET_UNKNOWN(ret);
  102
+		return ret_error;
  103
+	}
  104
+
  105
+
  106
+	}
  107
+
  108
+
  109
+	if (cherokee_connection_poll_is_set (&conn->polling_aim))
  110
+		return ret_egain;
  111
+
  112
+	return ret_ok;
  113
+}
36  cherokee/protocol_http.h
... ...
@@ -0,0 +1,36 @@
  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
+#ifndef CHEROKEE_PROTOCOL_HTTP_H
  26
+#define CHEROKEE_PROTOCOL_HTTP_H
  27
+
  28
+#include "protocol.h"
  29
+
  30
+CHEROKEE_BEGIN_DECLS
  31
+
  32
+ret_t cherokee_protocol_http_dispatch (cherokee_protocol_t *proto);
  33
+
  34
+CHEROKEE_END_DECLS
  35
+
  36
+#endif /* CHEROKEE_PROTOCOL_HTTP_H */
33  cherokee/protocol_spdy.c
... ...
@@ -0,0 +1,33 @@
  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 "protocol_spdy.h"
  27
+
  28
+
  29
+ret_t
  30
+cherokee_protocol_spdy_dispatch (cherokee_protocol_t *proto)
  31
+{
  32
+	return ret_ok;
  33
+}
37  cherokee/protocol_spdy.h
... ...
@@ -0,0 +1,37 @@
  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
+#ifndef CHEROKEE_PROTOCOL_SPDY_H
  26
+#define CHEROKEE_PROTOCOL_SPDY_H
  27
+
  28
+#include "buffer.h"
  29
+#include "list.h"
  30
+
  31
+CHEROKEE_BEGIN_DECLS
  32
+
  33
+ret_t cherokee_protocol_spdy_dispatch (cherokee_protocol_t *proto);
  34
+
  35
+CHEROKEE_END_DECLS
  36
+
  37
+#endif /* CHEROKEE_PROTOCOL_SPDY_H */
26  cherokee/request-protected.h
@@ -125,9 +125,8 @@ struct cherokee_request {
125 125
 
126 126
 	/* Buffers
127 127
 	 */
128  
-	cherokee_buffer_t             incoming_header;  /* -> header               */
129  
-	cherokee_buffer_t             header_buffer;    /* <- header, -> post data */
130  
-	cherokee_buffer_t             buffer;           /* <- data                 */
  128
+	/* cherokee_buffer_t             header_buffer;    /\* <- header, -> post data *\/ */
  129
+	/* cherokee_buffer_t             buffer;           /\* <- data                 *\/ */
131 130
 
132 131
 	/* State
133 132
 	 */
@@ -140,6 +139,8 @@ struct cherokee_request {
140 139
 	/* Headers
141 140
 	 */
142 141
 	cherokee_header_t             header;
  142
+	cherokee_buffer_t             header_buffer_in;
  143
+	cherokee_buffer_t             header_buffer_out;
143 144
 
144 145
 	/* Encoders
145 146
 	 */
@@ -171,24 +172,10 @@ struct cherokee_request {
171 172
 	cherokee_http_auth_t          auth_type;           /* Auth type of the resource */
172 173
 	cherokee_http_auth_t          req_auth_type;       /* Auth type of the request  */
173 174
 
174  
-	/* Traffic
175  
-	 */
176  
-	off_t                         rx;                  /* Bytes received */
177  
-	size_t                        rx_partial;          /* RX partial counter */
178  
-	off_t                         tx;                  /* Bytes sent */
179  
-	size_t                        tx_partial;          /* TX partial counter */
180  
-	time_t                        traffic_next;        /* Time to update traffic */
181  
-
182 175
 	/* Post info
183 176
 	 */
184 177
 	cherokee_post_t               post;
185 178
 
186  
-	/* Net connection
187  
-	 */
188  
-	time_t                        timeout;
189  
-	time_t                        timeout_lapse;
190  
-	cherokee_buffer_t            *timeout_header;
191  
-
192 179
 	/* Polling
193 180
 	 */
194 181
 
@@ -317,9 +304,4 @@ ret_t cherokee_request_log                    (cherokee_request_t *conn);
317 304
 ret_t cherokee_request_update_vhost_traffic   (cherokee_request_t *conn);
318 305
 char *cherokee_request_print                  (cherokee_request_t *conn);
319 306
 
320  
-/* Transfers
321  
- */
322  
-void cherokee_request_rx_add                  (cherokee_request_t *conn, ssize_t rx);
323  
-void cherokee_request_tx_add                  (cherokee_request_t *conn, ssize_t tx);
324  
-
325 307
 #endif /* CHEROKEE_REQUEST_PROTECTED_H */
78  cherokee/request.c
@@ -117,9 +117,6 @@ cherokee_request_new  (cherokee_request_t **req)
117 117
 	n->tx_partial                = 0;
118 118
 	n->traffic_next              = 0;
119 119
 	n->validator                 = NULL;
120  
-	n->timeout                   = -1;
121  
-	n->timeout_lapse             = -1;
122  
-	n->timeout_header            = NULL;
123 120
 	n->expiration                = cherokee_expiration_none;
124 121
 	n->expiration_time           = 0;
125 122
 	n->expiration_prop           = cherokee_expiration_prop_none;
@@ -129,8 +126,7 @@ cherokee_request_new  (cherokee_request_t **req)
129 126
 	n->limit_blocked_until       = 0;
130 127
 
131 128
 	cherokee_buffer_init (&n->buffer);
132  
-	cherokee_buffer_init (&n->header_buffer);
133  
-	cherokee_buffer_init (&n->incoming_header);
  129
+	cherokee_buffer_init (&n->header_buffer_out);
134 130
 	cherokee_buffer_init (&n->encoder_buffer);
135 131
 	cherokee_buffer_init (&n->logger_real_ip);
136 132
 
@@ -198,8 +194,8 @@ cherokee_request_free (cherokee_request_t *req)
198 194
 
199 195
 	cherokee_buffer_mrproper (&req->pathinfo);
200 196
 	cherokee_buffer_mrproper (&req->buffer);
201  
-	cherokee_buffer_mrproper (&req->header_buffer);
202  
-	cherokee_buffer_mrproper (&req->incoming_header);
  197
+	cherokee_buffer_mrproper (&req->header_buffer_in);
  198
+	cherokee_buffer_mrproper (&req->header_buffer_out);
203 199
 	cherokee_buffer_mrproper (&req->query_string);
204 200
 	cherokee_buffer_mrproper (&req->encoder_buffer);
205 201
 
@@ -337,6 +333,7 @@ cherokee_request_clean (cherokee_request_t *req,
337 333
 	cherokee_buffer_clean (&req->query_string);
338 334
 	cherokee_buffer_clean (&req->self_trace);
339 335
 	cherokee_buffer_clean (&req->chunked_len);
  336
+	cherokee_buffer_clean (&req->header_buffer_out);
340 337
 
341 338
 	req->error_internal_code = http_unset;
342 339
 	cherokee_buffer_clean (&req->error_internal_url);
@@ -356,7 +353,6 @@ cherokee_request_clean (cherokee_request_t *req,
356 353
 
357 354
 	cherokee_header_clean (&req->header);
358 355
 	cherokee_buffer_clean (&req->buffer);
359  
-	cherokee_buffer_clean (&req->header_buffer);
360 356
 
361 357
 	if (reuse) {
362 358
 		/* Skip trailing CRLF (which may be sent by some HTTP clients)
@@ -365,15 +361,15 @@ cherokee_request_clean (cherokee_request_t *req,
365 361
 		 * handled in next request.  This may avoid a subsequent real
366 362
 		 * move_to_begin of the contents left in the buffer.
367 363
 		 */
368  
-		crlf_len = cherokee_buffer_cnt_spn (&req->incoming_header, header_len, CRLF);
  364
+		crlf_len = cherokee_buffer_cnt_spn (&req->header_buffer_in, header_len, CRLF);
369 365
 		header_len += (crlf_len <= MAX_HEADER_CRLF) ? crlf_len : 0;
370 366
 
371  
-		cherokee_buffer_move_to_begin (&req->incoming_header, header_len);
  367
+		cherokee_buffer_move_to_begin (&req->header_buffer_in, header_len);
372 368
 
373 369
 		TRACE (ENTRIES, "conn %p, %s headers\n", req,
374  
-		       !cherokee_buffer_is_empty (&req->incoming_header) ? "has" : "doesn't have");
  370
+		       !cherokee_buffer_is_empty (&req->header_buffer_in) ? "has" : "doesn't have");
375 371
 	} else {
376  
-		cherokee_buffer_clean (&req->incoming_header);
  372
+		cherokee_buffer_clean (&req->header_buffer_in);
377 373
 	}
378 374
 
379 375
 	return ret_ok;
@@ -383,20 +379,26 @@ cherokee_request_clean (cherokee_request_t *req,
383 379
 ret_t
384 380
 cherokee_request_clean_close (cherokee_request_t *req)
385 381
 {
386  
-	/* Close and clean the socket
387  
-	 */
388  
-	cherokee_socket_close (&req->socket);
389  
-	cherokee_socket_clean (&req->socket);
  382
+	// TODO: Implement properties clean
  383
+	//
  384
+	//
  385
+	return ret_ok;
390 386
 
391  
-	/* Make sure the connection Keep-Alive is disabled
392  
-	 */
393  
-	req->keepalive = 0;
394  
-	cherokee_buffer_clean (&req->incoming_header);
395 387
 
396  
-	/* Clean the connection object
397  
-	 */
398  
-	cherokee_request_clean (req, false);
399  
-	return ret_ok;
  388
+	/* /\* Close and clean the socket */
  389
+	/*  *\/ */
  390
+	/* cherokee_socket_close (&req->socket); */
  391
+	/* cherokee_socket_clean (&req->socket); */
  392
+
  393
+	/* /\* Make sure the connection Keep-Alive is disabled */
  394
+	/*  *\/ */
  395
+	/* req->keepalive = 0; */
  396
+	/* cherokee_buffer_clean (&req->incoming_header); */
  397
+
  398
+	/* /\* Clean the connection object */
  399
+	/*  *\/ */
  400
+	/* cherokee_request_clean (req, false); */
  401
+	/* return ret_ok; */
400 402
 }
401 403
 
402 404
 
@@ -944,7 +946,7 @@ cherokee_request_build_header (cherokee_request_t *req)
944 946
 
945 947
 	/* Try to get the headers from the handler
946 948
 	 */
947  
-	ret = cherokee_handler_add_headers (req->handler, &req->header_buffer);
  949
+	ret = cherokee_handler_add_headers (req->handler, &req->header_buffer_out);
948 950
 	if (unlikely (ret != ret_ok)) {
949 951
 		switch (ret) {
950 952
 		case ret_eof:
@@ -960,13 +962,13 @@ cherokee_request_build_header (cherokee_request_t *req)
960 962
 	/* Front-line Cache (in): Handler headers
961 963
 	 */
962 964
 	if (req->flcache.mode == flcache_mode_in) {
963  
-		cherokee_buffer_add_buffer (&req->flcache.header, &req->header_buffer);
  965
+		cherokee_buffer_add_buffer (&req->flcache.header, &req->header_buffer_out);
964 966
 
965 967
 		/* Add X-Cache miss
966 968
 		 */
967  
-		cherokee_buffer_add_str (&req->header_buffer, "X-Cache: MISS from ");
968  
-		cherokee_request_build_host_port_string (req, &req->header_buffer);
969  
-		cherokee_buffer_add_str (&req->header_buffer, CRLF);
  969
+		cherokee_buffer_add_str (&req->header_buffer_out, "X-Cache: MISS from ");
  970
+		cherokee_request_build_host_port_string (req, &req->header_buffer_out);
  971
+		cherokee_buffer_add_str (&req->header_buffer_out, CRLF);
970 972
 	}
971 973
 
972 974
 	/* Replies with no body cannot use chunked encoding
@@ -1008,7 +1010,7 @@ cherokee_request_build_header (cherokee_request_t *req)
1008 1010
 
1009 1011
 	/* Add handler headers
1010 1012
 	 */
1011  
-	cherokee_buffer_add_buffer (&req->buffer, &req->header_buffer);
  1013
+	cherokee_buffer_add_buffer (&req->buffer, &req->header_buffer_out);
1012 1014
 
1013 1015
 	/* Add the server headers (phase 2)
1014 1016
 	 */
@@ -1202,7 +1204,7 @@ cherokee_request_reading_check (cherokee_request_t *req)
1202 1204
 {
1203 1205
 	/* Check for too long headers
1204 1206
 	 */
1205  
-	if (req->incoming_header.len > MAX_HEADER_LEN) {
  1207
+	if (req->header_buffer_in.len > MAX_HEADER_LEN) {
1206 1208
 		req->error_code = http_request_entity_too_large;
1207 1209
 		return ret_error;
1208 1210
 	}
@@ -2175,7 +2177,7 @@ cherokee_request_get_request (cherokee_request_t *req)
2175 2177
 
2176 2178
 	/* Header parsing
2177 2179
 	 */
2178  
-	ret = cherokee_header_parse (&req->header, &req->incoming_header, &error_code);
  2180
+	ret = cherokee_header_parse (&req->header, &req->header_buffer_in, &error_code);
2179 2181
 	if (unlikely (ret < ret_ok)) {
2180 2182
 		goto error;
2181 2183
 	}
@@ -2696,7 +2698,7 @@ cherokee_request_open_request (cherokee_request_t *req)
2696 2698
 
2697 2699
 	/* Ensure the space for headers and I/O buffer
2698 2700
 	 */
2699  
-	cherokee_buffer_ensure_size (&req->header_buffer, 384);
  2701
+	cherokee_buffer_ensure_size (&req->header_buffer_out, 384);
2700 2702
 	cherokee_buffer_ensure_size (&req->buffer, DEFAULT_READ_SIZE+1);
2701 2703
 
2702 2704
 	/* Init the connection handler object
@@ -2775,11 +2777,11 @@ cherokee_request_clean_error_headers (cherokee_request_t *req)
2775 2777
 	char *begin;
2776 2778
 	char *end;
2777 2779
 
2778  
-	if (cherokee_buffer_is_empty (&req->header_buffer))
  2780
+	if (cherokee_buffer_is_empty (&req->header_buffer_out))
2779 2781
 		return ret_ok;
2780 2782
 
2781  
-	begin = strncasestrn_s (req->header_buffer.buf,
2782  
-				req->header_buffer.len,
  2783
+	begin = strncasestrn_s (req->header_buffer_out.buf,
  2784
+				req->header_buffer_out.len,
2783 2785
 				"Content-Length: ");
2784 2786
 	if (begin != NULL) {
2785 2787
 		end = strchr (begin+16, CHR_CR);
@@ -2789,8 +2791,8 @@ cherokee_request_clean_error_headers (cherokee_request_t *req)
2789 2791
 		if (end[1] == CHR_LF)
2790 2792
 			end++;
2791 2793
 
2792  
-		cherokee_buffer_remove_chunk (&req->header_buffer,
2793  
-					      begin - req->header_buffer.buf,
  2794
+		cherokee_buffer_remove_chunk (&req->header_buffer_out,
  2795
+					      begin - req->header_buffer_out.buf,
2794 2796
 					      (end-begin)+1);
2795 2797
 	}
2796 2798
 
1,254  cherokee/thread.c
@@ -471,7 +471,7 @@ finalize_request (cherokee_thread_t  *thread,
471 471
 
472 472
 	/* Update the timeout value
473 473
 	 */
474  
-	req->timeout = cherokee_bogonow_now + req->timeout_lapse;
  474
+	conn->timeout = cherokee_bogonow_now + conn->timeout_lapse;
475 475
 }
476 476
 
477 477
 
@@ -540,10 +540,10 @@ process_polling_connections (cherokee_thread_t *thd)
540 540
 
541 541
 		/* Has the connection expired?
542 542
 		 */
543  
-		if (req->timeout < cherokee_bogonow_now) {
  543
+		if (conn->timeout < cherokee_bogonow_now) {
544 544
 			TRACE (ENTRIES",polling,timeout",
545 545
 			       "processing polling conn (%p, %s): Time out\n",
546  
-			       req, cherokee_request_get_phase_str (req));
  546
+			       conn, cherokee_request_get_phase_str (req));
547 547
 
548 548
 			/* Information collection
549 549
 			 */
@@ -629,12 +629,15 @@ process_polling_connections (cherokee_thread_t *thd)
629 629
 static void
630 630
 process_active_connections (cherokee_thread_t *thd)
631 631
 {
632  
-	ret_t                     ret;
633  
-	off_t                     len;
634  
-	cherokee_list_t          *i, *tmp;
635  
-	cherokee_request_t       *req       = NULL;
636  
-	cherokee_server_t        *srv       = SRV(thd->server);
637  
-	cherokee_socket_status_t  blocking;
  632
+	ret_t                      ret;
  633
+	off_t                      len;
  634
+	cherokee_list_t           *i, *tmp1;
  635
+	cherokee_list_t           *j, *tmp2;
  636
+	cherokee_request_t        *req       = NULL;
  637
+	cherokee_connection_t     *conn      = NULL;
  638
+	cherokee_virtual_server_t *vsrv      = NULL;
  639
+	cherokee_server_t         *srv       = SRV(thd->server);
  640
+	cherokee_socket_status_t   blocking;
638 641
 
639 642
 #ifdef TRACE_ENABLED
640 643
 	if (cherokee_trace_is_tracing()) {
@@ -653,33 +656,21 @@ process_active_connections (cherokee_thread_t *thd)
653 656
 
654 657
 	/* Process active connections
655 658
 	 */
656  
-	list_for_each_safe (i, tmp, LIST(&thd->active_list)) {
657  
-		req = REQ(i);
658  
-
659  
-		TRACE (ENTRIES, "processing conn (%p), phase %d '%s', socket=%d\n",
660  
-		       req, req->phase, cherokee_request_get_phase_str (req), req->socket.socket);
  659
+	list_for_each_safe (i, tmp1, LIST(&thd->active_list)) {
  660
+		conn = CONN(i);
661 661
 
662  
-		/* Thread's properties
  662
+		/* Thread property: Current connection
663 663
 		 */
664  
-		if (REQ_VSRV(req)) {
665  
-			/* Current connection
666  
-			 */
667  
-			CHEROKEE_THREAD_PROP_SET (thread_connection_ptr, req);
  664
+		CHEROKEE_THREAD_PROP_SET (thread_connection_ptr, conn);
  665
+
668 666
 
669  
-			/* Error writer
670  
-			 */
671  
-			if (REQ_VSRV(req)->error_writer) {
672  
-				CHEROKEE_THREAD_PROP_SET (thread_error_writer_ptr,
673  
-							  REQ_VSRV(req)->error_writer);
674  
-			}
675  
-		}
676 667
 
677 668
 		/* Has the connection been too much time w/o any work
678 669
 		 */
679  
-		if (req->timeout < cherokee_bogonow_now) {
  670
+		if (conn->timeout < cherokee_bogonow_now) {
680 671
 			TRACE (ENTRIES",polling,timeout",
681 672
 			       "processing active conn (%p, %s): Time out\n",
682  
-			       req, cherokee_request_get_phase_str (req));
  673
+			       conn, cherokee_request_get_phase_str (conn));
683 674
 
684 675
 			/* The lingering close timeout expired.
685 676
 			 * Proceed to close the connection.
@@ -691,742 +682,785 @@ process_active_connections (cherokee_thread_t *thd)
691 682
 				continue;
692 683
 			}
693 684
 
694  
-			/* Information collection
695  
-			 */
696  
-			if (THREAD_SRV(thd)->collector != NULL) {
697  
-				cherokee_collector_log_timeout (THREAD_SRV(thd)->collector);
698  
-			}
  685
+				/* Information collection
  686
+				 */
  687
+				if (THREAD_SRV(thd)->collector != NULL) {
  688
+					cherokee_collector_log_timeout (THREAD_SRV(thd)->collector);
  689
+				}
699 690
 
700  
-			goto shutdown;
701  
-		}
  691
+				goto shutdown;
702 692
 
703  
-		/* Update the connection timeout
704  
-		 */
705  
-		if ((req->phase != phase_tls_handshake) &&
706  
-		    (req->phase != phase_reading_header) &&
707  
-		    (req->phase != phase_reading_post) &&
708  
-		    (req->phase != phase_shutdown) &&
709  
-		    (req->phase != phase_lingering))
710  
-		{
711  
-			cherokee_request_update_timeout (req);
712  
-		}
713 693
 
714  
-		/* Maybe update traffic counters
715  
-		 */
716  
-		if ((REQ_VSRV(req)->collector) &&
717  
-		    (req->traffic_next < cherokee_bogonow_now) &&
718  
-		    ((req->rx_partial != 0) || (req->tx_partial != 0)))
719  
-		{
720  
-			cherokee_request_update_vhost_traffic (req);
721  
-		}
722 694
 
723  
-		/* Traffic shaping limiter
724  
-		 */
725  
-		if (req->limit_blocked_until > 0) {
726  
-			cherokee_thread_retire_active_connection (thd, req);
727  
-			cherokee_limiter_add_conn (&thd->limiter, req);
728  
-			continue;
729  
-		}
730 695
 
731  
-		TRACE (ENTRIES, "conn on phase n=%d: %s\n",
732  
-		       req->phase, cherokee_request_get_phase_str (req));
733 696
 
734  
-		/* Phases
735  
-		 */
736  
-		switch (req->phase) {
737  
-		case phase_tls_handshake:
738  
-			blocking = socket_closed;
739  
-
740  
-			ret = cherokee_socket_init_tls (&req->socket, REQ_VSRV(req), req, &blocking);
741  
-			switch (ret) {
742  
-			case ret_eagain:
743  
-				switch (blocking) {
744  
-				case socket_reading:
745  
-					break;
746 697
 
747  
-				case socket_writing:
748  
-					break;
  698
+		list_for_each_safe (j, tmp2, LIST(conn->requests)) {
  699
+			req  = REQ(i);
  700
+			vsrv = REQ_VSRV(i);
749 701
 
750  
-				default:
751  
-					break;
752  
-				}
  702
+			TRACE (ENTRIES, "processing req (c=%p,r=%p), phase %d '%s', socket=%d\n",
  703
+			       conn, req, req->phase, cherokee_request_get_phase_str (req), req->socket.socket);
753 704
 
754  
-				continue;
  705
+			/* Thread properties: Current request
  706
+			 */
  707
+			CHEROKEE_THREAD_PROP_SET (thread_request_ptr, req);
755 708
 
756  
-			case ret_ok:
757  
-				TRACE(ENTRIES, "Handshake %s\n", "finished");
  709
+			/* Error writer */
  710
+			if ((vsrv != NULL) && (vsrv->error_writer != NULL)) {
  711
+				CHEROKEE_THREAD_PROP_SET (thread_error_writer_ptr, vsrv->error_writer);
  712
+			}
758 713
 
759  
-				/* Set mode and update timeout
760  
-				 */
761  
-				cherokee_request_update_timeout (req);
  714
+			/* Has the connection been too much time w/o any work
  715
+			 */
  716
+			if (conn->timeout < cherokee_bogonow_now) {
  717
+				TRACE (ENTRIES",polling,timeout",
  718
+				       "processing active conn (%p, %s): Time out\n",
  719
+				       req, cherokee_request_get_phase_str (req));
762 720
 
763  
-				req->phase = phase_reading_header;
764  
-				break;
  721
+				/* The lingering close timeout expired.
  722
+				 * Proceed to close the connection.
  723
+				 */
  724
+				if ((req->phase == phase_shutdown) ||
  725
+				    (req->phase == phase_lingering))
  726
+				{
  727
+					close_active_connection (thd, req, false);
  728
+					continue;
  729
+				}
765 730
 
766  
-			case ret_eof:
767  
-			case ret_error:
768  
-				goto shutdown;
  731
+				/* Information collection
  732
+				 */
  733
+				if (THREAD_SRV(thd)->collector != NULL) {
  734
+					cherokee_collector_log_timeout (THREAD_SRV(thd)->collector);
  735
+				}
769 736
 
770  
-			default:
771  
-				RET_UNKNOWN(ret);
772 737
 				goto shutdown;
773 738
 			}
774  
-			break;
775 739
 
776  
-		case phase_reading_header:
777  
-			/* Maybe the buffer has a request (previous pipelined)
  740
+			/* Update the connection timeout
778 741
 			 */
779  
-			if (! cherokee_buffer_is_empty (&req->incoming_header))
  742
+			if ((req->phase != phase_tls_handshake) &&
  743
+			    (req->phase != phase_reading_header) &&
  744
+			    (req->phase != phase_reading_post) &&
  745
+			    (req->phase != phase_shutdown) &&
  746
+			    (req->phase != phase_lingering))
780 747
 			{
781  
-				ret = cherokee_header_has_header (&req->header,
782  
-								  &req->incoming_header,
783  
-								  req->incoming_header.len);
784  
-				switch (ret) {
785  
-				case ret_ok:
786  
-					goto phase_reading_header_EXIT;
787  
-				case ret_not_found:
788  
-					break;
789  
-				case ret_error:
790  
-					goto shutdown;
791  
-				default:
792  
-					RET_UNKNOWN(ret);
793  
-					goto shutdown;
794  
-				}
795  
-			}
796  
-
797  
-			/* Read from the client
798  
-			 */
799  
-			ret = cherokee_request_recv (req,
800  
-						     &req->incoming_header,
801  
-						     DEFAULT_RECV_SIZE, &len);
802  
-			switch (ret) {
803  
-			case ret_ok:
804  
-				break;
805  
-			case ret_eagain:
806  
-				cherokee_thread_deactive_to_polling (thd, req);
807  
-				continue;
808  
-			case ret_eof:
809  
-			case ret_error:
810  
-				goto shutdown;
811  
-			default:
812  
-				RET_UNKNOWN(ret);
813  
-				goto shutdown;
  748
+				cherokee_request_update_timeout (req);
814 749
 			}
815 750
 
816  
-			/* Check security after read
  751
+			/* Maybe update traffic counters
817 752
 			 */
818  
-			ret = cherokee_request_reading_check (req);
819  
-			if (ret != ret_ok) {
820  
-				req->keepalive      = 0;
821  
-				req->phase          = phase_setup_connection;
822  
-				req->header.version = http_version_11;
823  
-				continue;
  753
+			if ((vsrv->collector) &&
  754
+			    (req->traffic_next < cherokee_bogonow_now) &&
  755
+			    ((req->rx_partial != 0) || (req->tx_partial != 0)))
  756
+			{
  757
+				cherokee_request_update_vhost_traffic (req);
824 758
 			}
825 759
 
826  
-			/* May it already has the full header
  760
+			/* Traffic shaping limiter
827 761
 			 */
828  
-			ret = cherokee_header_has_header (&req->header, &req->incoming_header, len+4);
829  
-			switch (ret) {
830  
-			case ret_ok:
831  
-				break;
832  
-			case ret_not_found:
833  
-				req->phase = phase_reading_header;
  762
+			if (req->limit_blocked_until > 0) {
  763
+				cherokee_thread_retire_active_connection (thd, req);
  764
+				cherokee_limiter_add_conn (&thd->limiter, req);
834 765
 				continue;
835  
-			case ret_error:
836  
-				goto shutdown;
837  
-			default:
838  
-				RET_UNKNOWN(ret);
839  
-				goto shutdown;
840 766
 			}
841 767
 
842  
-			/* fall down */
843  
-
844  
-		phase_reading_header_EXIT:
845  
-			req->phase = phase_processing_header;
  768
+			TRACE (ENTRIES, "conn on phase n=%d: %s\n",
  769
+			       req->phase, cherokee_request_get_phase_str (req));
846 770
 
847  
-			/* fall down */
848  
-
849  
-		case phase_processing_header:
850  
-			/* Get the request
  771
+			/* Phases
851 772
 			 */
852  
-			ret = cherokee_request_get_request (req);
853  
-			switch (ret) {
854  
-			case ret_ok:
855  
-				break;
  773
+			switch (req->phase) {
  774
+			case phase_tls_handshake:
  775
+				blocking = socket_closed;