[or-cvs] r19706: {torperf} Handle SIGINT by writing how far we've got with our request (torperf/trunk)
kloesing at seul.org
kloesing at seul.org
Wed Jun 10 22:02:55 UTC 2009
Author: kloesing
Date: 2009-06-10 18:02:55 -0400 (Wed, 10 Jun 2009)
New Revision: 19706
Modified:
torperf/trunk/trivsocks-client.c
Log:
Handle SIGINT by writing how far we've got with our request and exit.
Modified: torperf/trunk/trivsocks-client.c
===================================================================
--- torperf/trunk/trivsocks-client.c 2009-06-10 20:11:48 UTC (rev 19705)
+++ torperf/trunk/trivsocks-client.c 2009-06-10 22:02:55 UTC (rev 19706)
@@ -10,6 +10,7 @@
#include <stdarg.h>
#include <string.h>
#include <assert.h>
+#include <signal.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -252,6 +253,37 @@
return printf("%ld %ld ", t.tv_sec, t.tv_usec);
}
+// Timestamps of important events
+struct timeval starttime; // Connection process started
+struct timeval sockettime; // After socket is created
+struct timeval connecttime; // After socket is connected
+struct timeval negotiatetime; // After authentication methods are negotiated (SOCKS 5 only)
+struct timeval requesttime; // After SOCKS request is sent
+struct timeval responsetime; // After SOCKS response is received
+struct timeval datarequesttime; // After HTTP request is written
+struct timeval dataresponsetime; // After first response is received
+struct timeval datacompletetime; // After payload is complete
+
+// Data counters of SOCKS payload
+size_t read_bytes;
+size_t write_bytes;
+
+static void
+output_status_information(void)
+{
+ print_time(starttime);
+ print_time(sockettime);
+ print_time(connecttime);
+ print_time(negotiatetime);
+ print_time(requesttime);
+ print_time(responsetime);
+ print_time(datarequesttime);
+ print_time(dataresponsetime);
+ print_time(datacompletetime);
+
+ printf("%lu %lu\n", (unsigned long)write_bytes, (unsigned long)read_bytes);
+}
+
/** Send a resolve request for <b>hostname</b> to the Tor listening on
* <b>sockshost</b>:<b>socksport</b>. Store the resulting IPv4
* address (in host order) into *<b>result_addr</b>.
@@ -262,21 +294,6 @@
uint32_t *result_addr, char **result_hostname)
{
- // Timestamps of important events
- struct timeval starttime; // Connection process started
- struct timeval sockettime; // After socket is created
- struct timeval connecttime; // After socket is connected
- struct timeval negotiatetime; // After authentication methods are negotiated (SOCKS 5 only)
- struct timeval requesttime; // After SOCKS request is sent
- struct timeval responsetime; // After SOCKS response is received
- struct timeval datarequesttime; // After HTTP request is written
- struct timeval dataresponsetime; // After first response is received
- struct timeval datacompletetime; // After payload is complete
-
- // Data counters of SOCKS payload
- size_t read_bytes;
- size_t write_bytes;
-
int s;
struct sockaddr_in socksaddr;
char *req = NULL;
@@ -392,17 +409,8 @@
&datarequesttime, &dataresponsetime, &datacompletetime);
// Output status information
- print_time(starttime);
- print_time(sockettime);
- print_time(connecttime);
- print_time(negotiatetime);
- print_time(requesttime);
- print_time(responsetime);
- print_time(datarequesttime);
- print_time(dataresponsetime);
- print_time(datacompletetime);
+ output_status_information();
- printf("%lu %lu\n", (unsigned long)write_bytes, (unsigned long)read_bytes);
return 0;
}
@@ -414,6 +422,15 @@
exit(1);
}
+static void
+termination_handler(int signum)
+{
+ fprintf(stderr,"Received a timeout. Exiting.\n");
+ output_status_information();
+
+ exit(1);
+}
+
/** Entry point to tor-resolve */
int
main(int argc, char **argv)
@@ -427,6 +444,8 @@
char *result_hostname = NULL;
char *hostname = NULL, *filename = NULL;
+ signal(SIGINT, termination_handler);
+
arg = &argv[1];
n_args = argc-1;
More information about the tor-commits
mailing list