Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Cherokee: commits

[3847] cherokee/trunk: Adds support for custom timeouts.

 

 

Cherokee commits RSS feed   Index | Next | Previous | View Threaded


cherokee at cherokee-project

Nov 20, 2009, 1:28 AM

Post #1 of 1 (110 views)
Permalink
[3847] cherokee/trunk: Adds support for custom timeouts.

Revision: 3847
http://svn.cherokee-project.com/changeset/3847
Author: alo
Date: 2009-11-20 10:28:51 +0100 (Fri, 20 Nov 2009)

Log Message:
-----------
Adds support for custom timeouts. Now rules can set a timeouts to the
connections matching them. It works in the very same way as expiration
dates, or custom document root values.

Modified Paths:
--------------
cherokee/trunk/admin/PageEntry.py
cherokee/trunk/cherokee/config_entry.c
cherokee/trunk/cherokee/config_entry.h
cherokee/trunk/cherokee/connection-protected.h
cherokee/trunk/cherokee/connection.c
cherokee/trunk/cherokee/nullable.h
cherokee/trunk/cherokee/thread.c
cherokee/trunk/cherokee/virtual_server.c

Modified: cherokee/trunk/admin/PageEntry.py
===================================================================
--- cherokee/trunk/admin/PageEntry.py 2009-11-20 09:25:30 UTC (rev 3846)
+++ cherokee/trunk/admin/PageEntry.py 2009-11-20 09:28:51 UTC (rev 3847)
@@ -13,6 +13,7 @@
N_ = lambda x: x

NOTE_DOCUMENT_ROOT = N_('Allows to specify an alternative document root path.')
+NOTE_TIMEOUT = N_('Apply a custom timeout to the connections matching this rule.')
NOTE_HANDLER = N_('How the connection will be handled.')
NOTE_HTTPS_ONLY = N_('Enable to allow access to the resource only by https.')
NOTE_ALLOW_FROM = N_('List of IPs and subnets allowed to access the resource.')
@@ -28,6 +29,7 @@
("vserver!(\d+)!rule!(\d+)!document_root", (validations.is_dev_null_or_local_dir_exists, 'cfg')),
("vserver!(\d+)!rule!(\d+)!allow_from", validations.is_ip_or_netmask_list),
("vserver!(\d+)!rule!(\d+)!rate", validations.is_number_gt_0),
+ ("vserver!(\d+)!rule!(\d+)!timeout", validations.is_number_gt_0),
("vserver!(\d+)!rule!(\d+)!expiration!time", validations.is_time)
]

@@ -160,6 +162,8 @@
if not props or props.show_document_root:
self.AddPropEntry (table, _('Document Root'), '%s!document_root'%(pre), _(NOTE_DOCUMENT_ROOT), optional=True)

+ self.AddPropEntry (table, _('Timeout'), '%s!timeout'%(pre), _(NOTE_TIMEOUT), optional=True)
+
if e:
tabs += [(_('Handler'), str(table) + e)]
else:

Modified: cherokee/trunk/cherokee/config_entry.c
===================================================================
--- cherokee/trunk/cherokee/config_entry.c 2009-11-20 09:25:30 UTC (rev 3846)
+++ cherokee/trunk/cherokee/config_entry.c 2009-11-20 09:28:51 UTC (rev 3847)
@@ -70,6 +70,9 @@
entry->limit_bps = 0;
entry->no_log = NULLB_NULL;

+ entry->timeout_lapse = NULLI_NULL;
+ entry->timeout_header = NULL;
+
return ret_ok;
}

@@ -203,6 +206,12 @@
entry->no_log = source->no_log;
}

+ if (NULLI_IS_NULL(entry->timeout_lapse) && (source->timeout_lapse != NULL))
+ {
+ entry->timeout_lapse = source->timeout_lapse;
+ entry->timeout_header = source->timeout_header;
+ }
+
return ret_ok;
}

@@ -226,5 +235,11 @@
printf ("limit bps: %d\n", entry->limit_bps);
printf ("no_log: %s\n", NULLB_TO_STR(entry->no_log));

+ if (NULLI_IS_NULL(entry->timeout_lapse)) {
+ printf ("timeout custom: no\n");
+ } else {
+ printf ("timeout custom: %d\n", entry->timeout_lapse);
+ }
+
return ret_ok;
}

Modified: cherokee/trunk/cherokee/config_entry.h
===================================================================
--- cherokee/trunk/cherokee/config_entry.h 2009-11-20 09:25:30 UTC (rev 3846)
+++ cherokee/trunk/cherokee/config_entry.h 2009-11-20 09:28:51 UTC (rev 3847)
@@ -84,6 +84,11 @@
/* Traffic shaping
*/
cuint_t limit_bps;
+
+ /* Timeout
+ */
+ cherokee_null_int_t timeout_lapse;
+ cherokee_buffer_t *timeout_header;
} cherokee_config_entry_t;

#define CONF_ENTRY(x) ((cherokee_config_entry_t *)(x))

Modified: cherokee/trunk/cherokee/connection-protected.h
===================================================================
--- cherokee/trunk/cherokee/connection-protected.h 2009-11-20 09:25:30 UTC (rev 3846)
+++ cherokee/trunk/cherokee/connection-protected.h 2009-11-20 09:28:51 UTC (rev 3847)
@@ -185,6 +185,9 @@
uint32_t keepalive;
time_t timeout;

+ time_t timeout_lapse;
+ cherokee_buffer_t *timeout_header;
+
/* Polling
*/
int polling_fd;

Modified: cherokee/trunk/cherokee/connection.c
===================================================================
--- cherokee/trunk/cherokee/connection.c 2009-11-20 09:25:30 UTC (rev 3846)
+++ cherokee/trunk/cherokee/connection.c 2009-11-20 09:28:51 UTC (rev 3847)
@@ -116,6 +116,8 @@
n->traffic_next = 0;
n->validator = NULL;
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;
@@ -247,7 +249,6 @@
BIT_UNSET (conn->options, conn_op_tcp_cork);
}

- conn->timeout = -1;
conn->phase = phase_reading_header;
conn->auth_type = http_auth_nothing;
conn->req_auth_type = http_auth_nothing;
@@ -637,7 +638,7 @@

} else if (conn->handler && (conn->keepalive > 0)) {
cherokee_buffer_add_str (buffer, "Connection: Keep-Alive"CRLF);
- cherokee_buffer_add_buffer (buffer, &CONN_SRV(conn)->timeout_header);
+ cherokee_buffer_add_buffer (buffer, conn->timeout_header);
} else {
cherokee_buffer_add_str (buffer, "Connection: close"CRLF);
}
@@ -2500,8 +2501,9 @@

/* Shortcut: Don't render if not tracing
*/
- if (! cherokee_trace_is_tracing())
+ if (! cherokee_trace_is_tracing()) {
return "";
+ }

/* Render
*/

Modified: cherokee/trunk/cherokee/nullable.h
===================================================================
--- cherokee/trunk/cherokee/nullable.h 2009-11-20 09:25:30 UTC (rev 3846)
+++ cherokee/trunk/cherokee/nullable.h 2009-11-20 09:28:51 UTC (rev 3847)
@@ -33,12 +33,16 @@
CHEROKEE_BEGIN_DECLS

typedef int cherokee_null_bool_t;
+typedef int cherokee_null_int_t;

#define NULLB_NULL 0xFC
#define NULLB_TO_BOOL(x) ((x) & 0x3)
#define NULLB_IS_NULL(x) ((x) & NULLB_NULL)
#define NULLB_TO_STR(x) (NULLB_IS_NULL(x) ? "NULL" : ((x) ? "True" : "False"))

+#define NULLI_NULL INT_MAX
+#define NULLI_IS_NULL(x) ((x) == NULLI_NULL)
+
CHEROKEE_END_DECLS

#endif /* CHEROKEE_NULLABLE_H */

Modified: cherokee/trunk/cherokee/thread.c
===================================================================
--- cherokee/trunk/cherokee/thread.c 2009-11-20 09:25:30 UTC (rev 3846)
+++ cherokee/trunk/cherokee/thread.c 2009-11-20 09:28:51 UTC (rev 3847)
@@ -333,8 +333,9 @@
*/
cherokee_connection_clean_close (conn);

- if (thread->conns_num > 0)
+ if (thread->conns_num > 0) {
thread->conns_num--;
+ }

/* Add it to the reusable list
*/
@@ -433,8 +434,6 @@
static void
maybe_purge_closed_connection (cherokee_thread_t *thread, cherokee_connection_t *conn)
{
- cherokee_server_t *srv = SRV(thread->server);
-
/* Log if it was delayed and update vserver traffic counters
*/
cherokee_connection_update_vhost_traffic (conn);
@@ -451,19 +450,20 @@

conn->keepalive--;

+ /* Flush any buffered data
+ */
+ if (conn->options & conn_op_tcp_cork) {
+ cherokee_socket_flush (&conn->socket);
+ }
+
/* Clean the connection
*/
cherokee_connection_clean (conn);
conn_set_mode (thread, conn, socket_reading);

- /* Flush any buffered data
- */
- if (conn->options & conn_op_tcp_cork)
- cherokee_socket_flush (&conn->socket);
-
/* Update the timeout value
*/
- conn->timeout = cherokee_bogonow_now + srv->timeout;
+ conn->timeout = cherokee_bogonow_now + conn->timeout_lapse;
}


@@ -622,7 +622,11 @@
if ((conn->phase != phase_reading_header) &&
(conn->phase != phase_lingering))
{
- conn->timeout = cherokee_bogonow_now + srv->timeout;
+ if (conn->timeout_lapse == -1) {
+ conn->timeout = cherokee_bogonow_now + srv->timeout;
+ } else {
+ conn->timeout = cherokee_bogonow_now + conn->timeout_lapse;
+ }
}

/* Maybe update traffic counters
@@ -991,6 +995,13 @@
*/
cherokee_connection_set_rate (conn, &entry);

+ /* Custom timeout
+ */
+ if (! NULLI_IS_NULL(entry.timeout_lapse)) {
+ conn->timeout_lapse = entry.timeout_lapse;
+ conn->timeout_header = entry.timeout_header;
+ }
+
/* Create the handler
*/
ret = cherokee_connection_create_handler (conn, &entry);
@@ -1842,9 +1853,14 @@
new_connection->server = server;
new_connection->vserver = VSERVER(server->vservers.prev);

- new_connection->timeout = cherokee_bogonow_now + THREAD_SRV(thd)->timeout;
new_connection->traffic_next = cherokee_bogonow_now + DEFAULT_TRAFFIC_UPDATE;

+ /* Set the default server timeout
+ */
+ new_connection->timeout = cherokee_bogonow_now + server->timeout;
+ new_connection->timeout_lapse = server->timeout;
+ new_connection->timeout_header = &server->timeout_header;
+
*conn = new_connection;
return ret_ok;
}

Modified: cherokee/trunk/cherokee/virtual_server.c
===================================================================
--- cherokee/trunk/cherokee/virtual_server.c 2009-11-20 09:25:30 UTC (rev 3846)
+++ cherokee/trunk/cherokee/virtual_server.c 2009-11-20 09:28:51 UTC (rev 3847)
@@ -372,10 +372,20 @@
if (equal_buf_str (&conf->val, "1")) {
entry->no_log = true;
}
+
+ } else if (equal_buf_str (&conf->key, "timeout")) {
+ entry->timeout_lapse = atoi(conf->val.buf);
+
+ if (entry->timeout_header != NULL) {
+ cherokee_buffer_free (entry->timeout_header);
+ }
+ cherokee_buffer_new (&entry->timeout_header);
+ cherokee_buffer_add_va (entry->timeout_header, "Keep-Alive: timeout=%d"CRLF, entry->timeout_lapse);

} else if (equal_buf_str (&conf->key, "match")) {
/* Ignore: Previously handled
*/
+
} else {
LOG_CRITICAL (CHEROKEE_ERROR_VSERVER_RULE_UNKNOWN_KEY,
conf->key.buf, vserver->priority, rule_prio);

Cherokee commits RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.