Add new config option: keep-alive-timeout.
authorFabian Keil <fk@fabiankeil.de>
Thu, 13 Nov 2008 09:08:42 +0000 (09:08 +0000)
committerFabian Keil <fk@fabiankeil.de>
Thu, 13 Nov 2008 09:08:42 +0000 (09:08 +0000)
gateway.c
gateway.h
loadcfg.c

index b1a162b..77ff47a 100644 (file)
--- a/gateway.c
+++ b/gateway.c
@@ -1,4 +1,4 @@
-const char gateway_rcs[] = "$Id: gateway.c,v 1.40 2008/11/08 15:14:05 fabiankeil Exp $";
+const char gateway_rcs[] = "$Id: gateway.c,v 1.41 2008/11/08 15:29:58 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/gateway.c,v $
@@ -34,6 +34,9 @@ const char gateway_rcs[] = "$Id: gateway.c,v 1.40 2008/11/08 15:14:05 fabiankeil
  *
  * Revisions   :
  *    $Log: gateway.c,v $
+ *    Revision 1.41  2008/11/08 15:29:58  fabiankeil
+ *    Unify two debug messages.
+ *
  *    Revision 1.40  2008/11/08 15:14:05  fabiankeil
  *    Fix duplicated debugging check.
  *
@@ -310,8 +313,7 @@ static const char socks_userid[] = "anonymous";
 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
 
 #define MAX_REUSABLE_CONNECTIONS 100
-/* XXX: should be a config option. */
-#define CONNECTION_KEEP_ALIVE_TIMEOUT 3 * 60
+int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
 
 struct reusable_connection
 {
@@ -652,13 +654,14 @@ static void close_unusable_connections(void)
       {
          time_t time_open = time(NULL) - reusable_connection[slot].timestamp;
 
-         if (CONNECTION_KEEP_ALIVE_TIMEOUT < time_open)
+         if (keep_alive_timeout < time_open)
          {
             log_error(LOG_LEVEL_CONNECT,
                "The connection to %s:%d in slot %d timed out. "
-               "Closing socket %d.", reusable_connection[slot].host,
+               "Closing socket %d. Timeout is: %d.",
+               reusable_connection[slot].host,
                reusable_connection[slot].port, slot,
-               reusable_connection[slot].sfd);
+               reusable_connection[slot].sfd, keep_alive_timeout);
             close_socket(reusable_connection[slot].sfd);
             mark_connection_closed(&reusable_connection[slot]);
             continue;
@@ -832,6 +835,25 @@ static int mark_connection_unused(jb_socket sfd)
    return socket_found;
 
 }
+
+
+/*********************************************************************
+ *
+ * Function    :  set_keep_alive_timeout
+ *
+ * Description :  Sets the timeout after which open
+ *                connections will no longer be reused.
+ *
+ * Parameters  :
+ *          1  :  timeout = The timeout in seconds.
+ *
+ * Returns     :  void
+ *
+ *********************************************************************/
+void set_keep_alive_timeout(int timeout)
+{
+   keep_alive_timeout = timeout;
+}
 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
 
 
index c5f83a2..4b054ca 100644 (file)
--- a/gateway.h
+++ b/gateway.h
@@ -1,6 +1,6 @@
 #ifndef GATEWAY_H_INCLUDED
 #define GATEWAY_H_INCLUDED
-#define GATEWAY_H_VERSION "$Id: gateway.h,v 1.9 2006/07/18 14:48:46 david__schmidt Exp $"
+#define GATEWAY_H_VERSION "$Id: gateway.h,v 1.10 2008/10/09 18:21:41 fabiankeil Exp $"
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/gateway.h,v $
  *
  * Revisions   :
  *    $Log: gateway.h,v $
+ *    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.
+ *
  *    Revision 1.9  2006/07/18 14:48:46  david__schmidt
  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
  *    with what was really the latest development (the v_3_0_branch branch)
@@ -104,6 +108,14 @@ extern jb_socket forwarded_connect(const struct forward_spec * fwd,
                                    struct http_request *http, 
                                    struct client_state *csp);
 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
+
+/*
+ * Default number of seconds after which an
+ * open connection will no longer be reused.
+ */
+#define DEFAULT_KEEP_ALIVE_TIMEOUT 180
+
+extern void set_keep_alive_timeout(int timeout);
 extern void initialize_reusable_connections(void);
 extern void forget_connection(jb_socket sfd);
 extern void remember_connection(jb_socket sfd,
index 504ab22..a2e2cf4 100644 (file)
--- a/loadcfg.c
+++ b/loadcfg.c
@@ -1,4 +1,4 @@
-const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.79 2008/08/30 12:03:07 fabiankeil Exp $";
+const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.80 2008/08/31 15:59:03 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
@@ -35,6 +35,10 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.79 2008/08/30 12:03:07 fabiankeil
  *
  * Revisions   :
  *    $Log: loadcfg.c,v $
+ *    Revision 1.80  2008/08/31 15:59:03  fabiankeil
+ *    There's no reason to let remote toggling support depend
+ *    on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
+ *
  *    Revision 1.79  2008/08/30 12:03:07  fabiankeil
  *    Remove FEATURE_COOKIE_JAR.
  *
@@ -504,6 +508,7 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.79 2008/08/30 12:03:07 fabiankeil
 #include "encode.h"
 #include "urlmatch.h"
 #include "cgi.h"
+#include "gateway.h"
 
 const char loadcfg_h_rcs[] = LOADCFG_H_VERSION;
 
@@ -567,6 +572,7 @@ static struct file_list *current_configfile = NULL;
 #define hash_forward_socks5              3963965522ul /* "forward-socks5" */
 #define hash_forwarded_connect_retries    101465292ul /* "forwarded-connect-retries" */
 #define hash_hostname                      10308071ul /* "hostname" */
+#define hash_keep_alive_timeout          3878599515ul /* "keep-alive-timeout" */
 #define hash_listen_address              1255650842ul /* "listen-address" */
 #define hash_logdir                          422889ul /* "logdir" */
 #define hash_logfile                        2114766ul /* "logfile" */
@@ -720,6 +726,9 @@ struct configuration_spec * load_config(void)
    unsigned long linenum = 0;
    int i;
    char *logfile = NULL;
+#ifdef FEATURE_CONNECTION_KEEP_ALIVE
+   int keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
+#endif
 
    if ( !check_file_changed(current_configfile, configfile, &fs))
    {
@@ -1327,6 +1336,27 @@ struct configuration_spec * load_config(void)
             }
             continue;
 
+/* *************************************************************************
+ * keep-alive-timeout timeout
+ * *************************************************************************/
+#ifdef FEATURE_CONNECTION_KEEP_ALIVE
+         case hash_keep_alive_timeout :
+            if (*arg != '\0')
+            {
+               int timeout = atoi(arg);
+               if (0 <= timeout)
+               {
+                  keep_alive_timeout = timeout;
+               }
+               else
+               {
+                  log_error(LOG_LEVEL_FATAL,
+                     "Invalid keep-alive-timeout value: %s.", arg);
+               }
+            }
+            continue;
+#endif
+
 /* *************************************************************************
  * listen-address [ip][:port]
  * *************************************************************************/
@@ -1656,6 +1686,9 @@ struct configuration_spec * load_config(void)
    fclose(configfp);
 
    set_debug_level(config->debug);
+#ifdef FEATURE_CONNECTION_KEEP_ALIVE
+   set_keep_alive_timeout(keep_alive_timeout);
+#endif
 
    freez(config->logfile);