Keep track of how many request are sent through a server connection
authorFabian Keil <fk@fabiankeil.de>
Sun, 21 Oct 2012 12:56:38 +0000 (12:56 +0000)
committerFabian Keil <fk@fabiankeil.de>
Sun, 21 Oct 2012 12:56:38 +0000 (12:56 +0000)
gateway.c
jcc.c
project.h

index 9ed7e72..dad4c40 100644 (file)
--- a/gateway.c
+++ b/gateway.c
@@ -1,4 +1,4 @@
-const char gateway_rcs[] = "$Id: gateway.c,v 1.89 2012/10/17 18:11:40 fabiankeil Exp $";
+const char gateway_rcs[] = "$Id: gateway.c,v 1.90 2012/10/17 18:13:26 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/gateway.c,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/gateway.c,v $
@@ -228,6 +228,7 @@ void remember_connection(const struct reusable_connection *connection)
    reusable_connection[slot].request_sent = connection->request_sent;
    reusable_connection[slot].response_received = connection->response_received;
    reusable_connection[slot].keep_alive_timeout = connection->keep_alive_timeout;
    reusable_connection[slot].request_sent = connection->request_sent;
    reusable_connection[slot].response_received = connection->response_received;
    reusable_connection[slot].keep_alive_timeout = connection->keep_alive_timeout;
+   reusable_connection[slot].requests_sent_total = connection->requests_sent_total;
 
    assert(reusable_connection[slot].gateway_host == NULL);
    assert(reusable_connection[slot].gateway_port == 0);
 
    assert(reusable_connection[slot].gateway_host == NULL);
    assert(reusable_connection[slot].gateway_port == 0);
@@ -284,6 +285,7 @@ void mark_connection_closed(struct reusable_connection *closed_connection)
    closed_connection->request_sent = 0;
    closed_connection->response_received = 0;
    closed_connection->keep_alive_timeout = 0;
    closed_connection->request_sent = 0;
    closed_connection->response_received = 0;
    closed_connection->keep_alive_timeout = 0;
+   closed_connection->requests_sent_total = 0;
    closed_connection->forwarder_type = SOCKS_NONE;
    freez(closed_connection->gateway_host);
    closed_connection->gateway_port = 0;
    closed_connection->forwarder_type = SOCKS_NONE;
    freez(closed_connection->gateway_host);
    closed_connection->gateway_port = 0;
@@ -494,13 +496,14 @@ static jb_socket get_reusable_connection(const struct http_request *http,
             reusable_connection[slot].in_use = TRUE;
             sfd = reusable_connection[slot].sfd;
             log_error(LOG_LEVEL_CONNECT,
             reusable_connection[slot].in_use = TRUE;
             sfd = reusable_connection[slot].sfd;
             log_error(LOG_LEVEL_CONNECT,
-               "Found reusable socket %d for %s:%d in slot %d. "
-               "Timestamp made %d seconds ago. Timeout: %d. Latency: %d.",
+               "Found reusable socket %d for %s:%d in slot %d. Timestamp made %d "
+               "seconds ago. Timeout: %d. Latency: %d. Requests served: %d",
                sfd, reusable_connection[slot].host, reusable_connection[slot].port,
                slot, time(NULL) - reusable_connection[slot].timestamp,
                reusable_connection[slot].keep_alive_timeout,
                (int)(reusable_connection[slot].response_received -
                sfd, reusable_connection[slot].host, reusable_connection[slot].port,
                slot, time(NULL) - reusable_connection[slot].timestamp,
                reusable_connection[slot].keep_alive_timeout,
                (int)(reusable_connection[slot].response_received -
-               reusable_connection[slot].request_sent));
+               reusable_connection[slot].request_sent),
+               reusable_connection[slot].requests_sent_total);
             break;
          }
       }
             break;
          }
       }
diff --git a/jcc.c b/jcc.c
index ac6f282..282523c 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.398 2012/10/21 12:51:57 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.399 2012/10/21 12:53:33 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -1688,8 +1688,9 @@ static void chat(struct client_state *csp)
       && connection_destination_matches(&csp->server_connection, http, fwd))
    {
       log_error(LOG_LEVEL_CONNECT,
       && connection_destination_matches(&csp->server_connection, http, fwd))
    {
       log_error(LOG_LEVEL_CONNECT,
-         "Reusing server socket %u. Opened for %s.",
-         csp->server_connection.sfd, csp->server_connection.host);
+         "Reusing server socket %d connected to %s. Total requests: %u.",
+         csp->server_connection.sfd, csp->server_connection.host,
+         csp->server_connection.requests_sent_total);
    }
    else
    {
    }
    else
    {
@@ -1737,6 +1738,8 @@ static void chat(struct client_state *csp)
    }
 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
 
    }
 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
 
+   csp->server_connection.requests_sent_total++;
+
    if (fwd->forward_host || (http->ssl == 0))
    {
       int write_failure;
    if (fwd->forward_host || (http->ssl == 0))
    {
       int write_failure;
index 2b1ca3d..4ca2b52 100644 (file)
--- a/project.h
+++ b/project.h
@@ -1,7 +1,7 @@
 #ifndef PROJECT_H_INCLUDED
 #define PROJECT_H_INCLUDED
 /** Version string. */
 #ifndef PROJECT_H_INCLUDED
 #define PROJECT_H_INCLUDED
 /** Version string. */
-#define PROJECT_H_VERSION "$Id: project.h,v 1.186 2012/10/21 12:52:35 fabiankeil Exp $"
+#define PROJECT_H_VERSION "$Id: project.h,v 1.187 2012/10/21 12:53:33 fabiankeil Exp $"
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/project.h,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/project.h,v $
@@ -668,6 +668,11 @@ struct reusable_connection
     * connection will no longer be reused.
     */
    unsigned int keep_alive_timeout;
     * connection will no longer be reused.
     */
    unsigned int keep_alive_timeout;
+   /*
+    * Number of requests that were sent to this connection.
+    * This is currently only for debugging purposes.
+    */
+   unsigned int requests_sent_total;
 
    char *host;
    int  port;
 
    char *host;
    int  port;