even if no new requests are coming in.
-const char gateway_rcs[] = "$Id: gateway.c,v 1.45 2008/12/04 18:17:07 fabiankeil Exp $";
+const char gateway_rcs[] = "$Id: gateway.c,v 1.46 2008/12/13 11:07:23 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/gateway.c,v $
*
* Revisions :
* $Log: gateway.c,v $
+ * Revision 1.46 2008/12/13 11:07:23 fabiankeil
+ * Remove duplicated debugging checks
+ * in connection_destination_matches().
+ *
* Revision 1.45 2008/12/04 18:17:07 fabiankeil
* Fix some cparser warnings.
*
*
* Parameters : none
*
- * Returns : void
+ * Returns : Number of connections that are still alive.
*
*********************************************************************/
-static void close_unusable_connections(void)
+int close_unusable_connections(void)
{
unsigned int slot = 0;
+ int connections_alive = 0;
+
+ privoxy_mutex_lock(&connection_reuse_mutex);
for (slot = 0; slot < SZ(reusable_connection); slot++)
{
reusable_connection[slot].sfd, keep_alive_timeout);
close_socket(reusable_connection[slot].sfd);
mark_connection_closed(&reusable_connection[slot]);
- continue;
}
-
- if (!socket_is_still_usable(reusable_connection[slot].sfd))
+ else if (!socket_is_still_usable(reusable_connection[slot].sfd))
{
log_error(LOG_LEVEL_CONNECT,
"The connection to %s:%d in slot %d is no longer usable. "
reusable_connection[slot].sfd);
close_socket(reusable_connection[slot].sfd);
mark_connection_closed(&reusable_connection[slot]);
- continue;
+ }
+ else
+ {
+ connections_alive++;
}
}
}
+
+ privoxy_mutex_unlock(&connection_reuse_mutex);
+
+ return connections_alive;
+
}
jb_socket sfd = JB_INVALID_SOCKET;
unsigned int slot = 0;
- privoxy_mutex_lock(&connection_reuse_mutex);
-
close_unusable_connections();
+ privoxy_mutex_lock(&connection_reuse_mutex);
+
for (slot = 0; slot < SZ(reusable_connection); slot++)
{
if (!reusable_connection[slot].in_use
#ifndef GATEWAY_H_INCLUDED
#define GATEWAY_H_INCLUDED
-#define GATEWAY_H_VERSION "$Id: gateway.h,v 1.10 2008/10/09 18:21:41 fabiankeil Exp $"
+#define GATEWAY_H_VERSION "$Id: gateway.h,v 1.11 2008/11/13 09:08:42 fabiankeil Exp $"
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/gateway.h,v $
*
* Revisions :
* $Log: gateway.h,v $
+ * Revision 1.11 2008/11/13 09:08:42 fabiankeil
+ * Add new config option: keep-alive-timeout.
+ *
* Revision 1.10 2008/10/09 18:21:41 fabiankeil
* Flush work-in-progress changes to keep outgoing connections
* alive where possible. Incomplete and mostly #ifdef'd out.
extern void remember_connection(jb_socket sfd,
const struct http_request *http,
const struct forward_spec *fwd);
+extern int close_unusable_connections(void);
#endif /* FEATURE_CONNECTION_KEEP_ALIVE */
-const char jcc_rcs[] = "$Id: jcc.c,v 1.213 2008/12/15 18:45:51 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.214 2008/12/20 14:53:55 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
*
* Revisions :
* $Log: jcc.c,v $
+ * Revision 1.214 2008/12/20 14:53:55 fabiankeil
+ * Add config option socket-timeout to control the time
+ * Privoxy waits for data to arrive on a socket. Useful
+ * in case of stale ssh tunnels or when fuzz-testing.
+ *
* Revision 1.213 2008/12/15 18:45:51 fabiankeil
* When logging crunches, log the whole URL, so one can easily
* differentiate between vanilla HTTP and CONNECT requests.
}
+/*********************************************************************
+ *
+ * Function : wait_for_alive_connections
+ *
+ * Description : Waits for alive connections to timeout.
+ *
+ * Parameters : N/A
+ *
+ * Returns : N/A
+ *
+ *********************************************************************/
+static void wait_for_alive_connections()
+{
+ int connections_alive = close_unusable_connections();
+
+ while (0 < connections_alive)
+ {
+ log_error(LOG_LEVEL_CONNECT,
+ "Waiting for %d connections to timeout.",
+ connections_alive);
+ sleep(60);
+ connections_alive = close_unusable_connections();
+ }
+
+ log_error(LOG_LEVEL_CONNECT, "No connections to wait for left.");
+
+}
+
/*********************************************************************
*
* Function : serve
if (csp->sfd != JB_INVALID_SOCKET)
{
#ifdef FEATURE_CONNECTION_KEEP_ALIVE
+ static int monitor_thread_running = 0;
+
if ((csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
&& (csp->flags & CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE))
{
remember_connection(csp->sfd, csp->http, forward_url(csp, csp->http));
+ privoxy_mutex_lock(&connection_reuse_mutex);
+ if (!monitor_thread_running)
+ {
+ monitor_thread_running = 1;
+ privoxy_mutex_unlock(&connection_reuse_mutex);
+ wait_for_alive_connections();
+ privoxy_mutex_lock(&connection_reuse_mutex);
+ monitor_thread_running = 0;
+ }
+ privoxy_mutex_unlock(&connection_reuse_mutex);
}
else
{