-const char gateway_rcs[] = "$Id: gateway.c,v 1.50 2009/05/10 10:19:23 fabiankeil Exp $";
+const char gateway_rcs[] = "$Id: gateway.c,v 1.51 2009/05/13 18:20:54 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/gateway.c,v $
*
* Revisions :
* $Log: gateway.c,v $
+ * Revision 1.51 2009/05/13 18:20:54 fabiankeil
+ * There's no reason for keep_alive_timeout to be signed.
+ *
* Revision 1.50 2009/05/10 10:19:23 fabiankeil
* Reenable server-side-only keep-alive support, but only share
* outgoing connections if the connection-sharing option is set.
* 1 : sfd = Open socket to remember.
* 2 : http = The destination for the connection.
* 3 : fwd = The forwarder settings used.
+ * 4 : timeout = Number of seconds after which the
+ * connection shouldn't be reused.
*
* Returns : void
*
*********************************************************************/
-void remember_connection(jb_socket sfd, const struct http_request *http,
- const struct forward_spec *fwd)
+void remember_connection(jb_socket sfd,
+ const struct http_request *http,
+ const struct forward_spec *fwd,
+ unsigned int timeout)
{
unsigned int slot = 0;
int free_slot_found = FALSE;
reusable_connection[slot].port = http->port;
reusable_connection[slot].in_use = 0;
reusable_connection[slot].timestamp = time(NULL);
+ reusable_connection[slot].keep_alive_timeout = timeout;
assert(NULL != fwd);
assert(reusable_connection[slot].gateway_host == NULL);
freez(closed_connection->host);
closed_connection->port = 0;
closed_connection->timestamp = 0;
+ closed_connection->keep_alive_timeout = 0;
closed_connection->forwarder_type = SOCKS_NONE;
freez(closed_connection->gateway_host);
closed_connection->gateway_port = 0;
{
time_t time_open = time(NULL) - reusable_connection[slot].timestamp;
- if (keep_alive_timeout < time_open)
+ if (reusable_connection[slot].keep_alive_timeout < time_open)
{
log_error(LOG_LEVEL_CONNECT,
"The connection to %s:%d in slot %d timed out. "
"Closing socket %d. Timeout is: %d.",
reusable_connection[slot].host,
reusable_connection[slot].port, slot,
- reusable_connection[slot].sfd, keep_alive_timeout);
+ reusable_connection[slot].sfd,
+ reusable_connection[slot].keep_alive_timeout);
close_socket(reusable_connection[slot].sfd);
mark_connection_closed(&reusable_connection[slot]);
}
#ifndef GATEWAY_H_INCLUDED
#define GATEWAY_H_INCLUDED
-#define GATEWAY_H_VERSION "$Id: gateway.h,v 1.13 2009/05/10 10:12:30 fabiankeil Exp $"
+#define GATEWAY_H_VERSION "$Id: gateway.h,v 1.14 2009/05/13 18:20:54 fabiankeil Exp $"
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/gateway.h,v $
*
* Revisions :
* $Log: gateway.h,v $
+ * Revision 1.14 2009/05/13 18:20:54 fabiankeil
+ * There's no reason for keep_alive_timeout to be signed.
+ *
* Revision 1.13 2009/05/10 10:12:30 fabiankeil
* Initial keep-alive support for the client socket.
* Temporarily disable the server-side-only keep-alive code.
extern void forget_connection(jb_socket sfd);
extern void remember_connection(jb_socket sfd,
const struct http_request *http,
- const struct forward_spec *fwd);
+ const struct forward_spec *fwd,
+ unsigned int timeout);
extern int close_unusable_connections(void);
extern void mark_connection_closed(struct reusable_connection *closed_connection);
extern int connection_destination_matches(const struct reusable_connection *connection,
-const char jcc_rcs[] = "$Id: jcc.c,v 1.247 2009/05/10 10:19:23 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.248 2009/05/10 10:25:19 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
*
* Revisions :
* $Log: jcc.c,v $
+ * Revision 1.248 2009/05/10 10:25:19 fabiankeil
+ * Change wait_for_alive_connection() prototype to use (void).
+ *
* Revision 1.247 2009/05/10 10:19:23 fabiankeil
* Reenable server-side-only keep-alive support, but only share
* outgoing connections if the connection-sharing option is set.
}
#ifdef FEATURE_CONNECTION_KEEP_ALIVE
save_connection_destination(csp->sfd, http, fwd, &csp->server_connection);
+ csp->server_connection.keep_alive_timeout = (unsigned)csp->config->keep_alive_timeout;
}
#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
csp->sfd, csp->server_connection.host);
if ((csp->flags & CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE)
- && data_is_available(csp->cfd, csp->config->keep_alive_timeout)
+ && data_is_available(csp->cfd, (int)csp->server_connection.keep_alive_timeout)
&& socket_is_still_usable(csp->cfd))
{
log_error(LOG_LEVEL_CONNECT, "Client request arrived in "
if ((csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
{
remember_connection(csp->sfd, csp->http,
- forward_url(csp, csp->http));
+ forward_url(csp, csp->http),
+ csp->server_connection.keep_alive_timeout);
csp->sfd = JB_INVALID_SOCKET;
close_socket(csp->cfd);
csp->cfd = JB_INVALID_SOCKET;
-const char parsers_rcs[] = "$Id: parsers.c,v 1.154 2009/03/13 14:10:07 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.155 2009/05/10 10:12:30 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
*
* Revisions :
* $Log: parsers.c,v $
+ * Revision 1.155 2009/05/10 10:12:30 fabiankeil
+ * Initial keep-alive support for the client socket.
+ * Temporarily disable the server-side-only keep-alive code.
+ *
* Revision 1.154 2009/03/13 14:10:07 fabiankeil
* Fix some more harmless warnings on amd64.
*
#ifdef FEATURE_CONNECTION_KEEP_ALIVE
static jb_err server_save_content_length(struct client_state *csp, char **header);
+static jb_err server_keep_alive(struct client_state *csp, char **header);
#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
static jb_err client_host_adder (struct client_state *csp);
{ "Content-Encoding:", 17, server_content_encoding },
#ifdef FEATURE_CONNECTION_KEEP_ALIVE
{ "Content-Length:", 15, server_save_content_length },
+ { "Keep-Alive:", 11, server_keep_alive },
#else
{ "Keep-Alive:", 11, crumble },
#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
return JB_ERR_OK;
}
+
+#ifdef FEATURE_CONNECTION_KEEP_ALIVE
+/*********************************************************************
+ *
+ * Function : server_keep_alive
+ *
+ * Description : Stores the servers keep alive timeout.
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : header = On input, pointer to header to modify.
+ * On output, pointer to the modified header, or NULL
+ * to remove the header. This function frees the
+ * original string if necessary.
+ *
+ * Returns : JB_ERR_OK.
+ *
+ *********************************************************************/
+static jb_err server_keep_alive(struct client_state *csp, char **header)
+{
+ unsigned int keep_alive_timeout;
+ const char *timeout_position = strstr(*header, "timeout=");
+
+ if ((NULL != timeout_position)
+ && (1 != sscanf(timeout_position, "timeout=%u", &keep_alive_timeout)))
+ {
+ log_error(LOG_LEVEL_ERROR, "Couldn't parse: %s", *header);
+ }
+ else
+ {
+ if (keep_alive_timeout < csp->server_connection.keep_alive_timeout)
+ {
+ log_error(LOG_LEVEL_HEADER,
+ "Reducing keep-alive timeout from %u to %u.",
+ csp->server_connection.keep_alive_timeout, keep_alive_timeout);
+ csp->server_connection.keep_alive_timeout = keep_alive_timeout;
+ }
+ else
+ {
+ /* XXX: Is this log worthy? */
+ log_error(LOG_LEVEL_HEADER,
+ "Server keep-alive timeout is %u. Sticking with %u.",
+ keep_alive_timeout, csp->server_connection.keep_alive_timeout);
+ }
+ }
+
+ return JB_ERR_OK;
+}
+#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
+
+
+
/*********************************************************************
*
* Function : client_connection
#ifndef PROJECT_H_INCLUDED
#define PROJECT_H_INCLUDED
/** Version string. */
-#define PROJECT_H_VERSION "$Id: project.h,v 1.135 2009/05/10 10:19:23 fabiankeil Exp $"
+#define PROJECT_H_VERSION "$Id: project.h,v 1.136 2009/05/13 18:20:54 fabiankeil Exp $"
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/project.h,v $
*
* Revisions :
* $Log: project.h,v $
+ * Revision 1.136 2009/05/13 18:20:54 fabiankeil
+ * There's no reason for keep_alive_timeout to be signed.
+ *
* Revision 1.135 2009/05/10 10:19:23 fabiankeil
* Reenable server-side-only keep-alive support, but only share
* outgoing connections if the connection-sharing option is set.
jb_socket sfd;
int in_use;
time_t timestamp;
+ /*
+ * Number of seconds after which this
+ * connection will no longer be reused.
+ */
+ unsigned int keep_alive_timeout;
char *host;
int port;
int socket_timeout;
#ifdef FEATURE_CONNECTION_KEEP_ALIVE
- /* Number of seconds after which an open connection will no longer be reused. */
+ /* Maximum number of seconds after which an open connection will no longer be reused. */
unsigned int keep_alive_timeout;
#endif