diff options
author | Nick Mathewson <nickm@torproject.org> | 2003-04-16 17:04:58 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2003-04-16 17:04:58 +0000 |
commit | 33176c70a5b9bb345d96af22178c003e177b2bb9 (patch) | |
tree | 10336e1543ad7f638f0f147e65864ef7a3eb6e66 /src/or | |
parent | 0c61bc3756e833abe97999fa2a22b944a9ce3931 (diff) | |
download | tor-33176c70a5b9bb345d96af22178c003e177b2bb9.tar.gz tor-33176c70a5b9bb345d96af22178c003e177b2bb9.zip |
Factor out timeval-related functions.
svn:r237
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/circuit.c | 16 | ||||
-rw-r--r-- | src/or/command.c | 23 | ||||
-rw-r--r-- | src/or/connection.c | 41 | ||||
-rw-r--r-- | src/or/main.c | 6 | ||||
-rw-r--r-- | src/or/or.h | 1 |
5 files changed, 18 insertions, 69 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c index 17dcc0662e..cc9f51b9b1 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -53,8 +53,7 @@ circuit_t *circuit_new(aci_t p_aci, connection_t *p_conn) { circuit_t *circ; struct timeval now; - if(gettimeofday(&now,NULL) < 0) - return NULL; + my_gettimeofday(&now); circ = (circuit_t *)malloc(sizeof(circuit_t)); if(!circ) @@ -157,7 +156,7 @@ int circuit_init(circuit_t *circ, int aci_type, onion_layer_t *layer) { log(LOG_DEBUG,"circuit_init(): aci_type = %u.",aci_type); - gettimeofday(&start,NULL); + my_gettimeofday(&start); circ->n_aci = get_unique_aci_by_addr_port(circ->n_addr, circ->n_port, aci_type); if(!circ->n_aci) { @@ -165,19 +164,12 @@ int circuit_init(circuit_t *circ, int aci_type, onion_layer_t *layer) { return -1; } - gettimeofday(&end,NULL); + my_gettimeofday(&end); - if(end.tv_usec < start.tv_usec) { - end.tv_sec--; - end.tv_usec += 1000000; - } - time_passed = ((end.tv_sec - start.tv_sec)*1000000) + (end.tv_usec - start.tv_usec); - if(time_passed > 1000) { /* more than 1ms */ + if (tv_udiff(&start, &end) > 1000) {/* more than 1ms */ log(LOG_NOTICE,"circuit_init(): get_unique_aci just took %d us!",time_passed); } - - log(LOG_DEBUG,"circuit_init(): Chosen ACI %u.",circ->n_aci); /* keys */ diff --git a/src/or/command.c b/src/or/command.c index 878d26e0a0..2ec250000b 100644 --- a/src/or/command.c +++ b/src/or/command.c @@ -14,24 +14,14 @@ void command_time_process_cell(cell_t *cell, connection_t *conn, *num += 1; - if(gettimeofday(&start,NULL) < 0) { - log(LOG_ERR,"command_time_process_cell(): gettimeofday failed."); - return; - } + my_gettimeofday(&start); (*func)(cell, conn); - if(gettimeofday(&end,NULL) < 0) { - log(LOG_ERR,"command_time_process_cell(): gettimeofday failed."); - return; - } + my_gettimeofday(&end); + time_passed = tv_udiff(&start, &end) ; - if(end.tv_usec < start.tv_usec) { - end.tv_sec--; - end.tv_usec += 1000000; - } - time_passed = ((end.tv_sec - start.tv_sec)*1000000) + (end.tv_usec - start.tv_usec); - if(time_passed > 5000) { /* more than 5ms */ + if (time_passed > 5000) { /* more than 5ms */ log(LOG_INFO,"command_time_process_cell(): That call just took %d ms.",time_passed/1000); } *time += time_passed; @@ -43,10 +33,7 @@ void command_process_cell(cell_t *cell, connection_t *conn) { static long current_second = 0; /* from previous calls to gettimeofday */ struct timeval now; - if(gettimeofday(&now,NULL) < 0) { - log(LOG_ERR,"command_process_cell(): gettimeofday failed."); - return; - } + my_gettimeofday(&now); if(now.tv_sec > current_second) { /* the second has rolled over */ /* print stats */ diff --git a/src/or/connection.c b/src/or/connection.c index 20b29dfa2c..c15eb00100 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -61,31 +61,6 @@ char *conn_state_to_string[][15] = { /********* END VARIABLES ************/ -/**************************************************************/ - -int tv_cmp(struct timeval *a, struct timeval *b) { - if (a->tv_sec > b->tv_sec) - return 1; - if (a->tv_sec < b->tv_sec) - return -1; - if (a->tv_usec > b->tv_usec) - return 1; - if (a->tv_usec < b->tv_usec) - return -1; - return 0; -} - -void tv_add(struct timeval *a, struct timeval *b) { - a->tv_usec += b->tv_usec; - a->tv_sec += b->tv_sec + (a->tv_usec / 1000000); - a->tv_usec %= 1000000; -} - -void tv_addms(struct timeval *a, long ms) { - a->tv_usec += (ms * 1000) % 1000000; - a->tv_sec += ((ms * 1000) / 1000000) + (a->tv_usec / 1000000); - a->tv_usec %= 1000000; -} /**************************************************************/ @@ -93,8 +68,7 @@ connection_t *connection_new(int type) { connection_t *conn; struct timeval now; - if(gettimeofday(&now,NULL) < 0) - return NULL; + my_gettimeofday(&now); conn = (connection_t *)malloc(sizeof(connection_t)); if(!conn) @@ -328,8 +302,8 @@ int connection_read_to_buf(connection_t *conn) { assert(conn->receiver_bucket < 0); } - if(gettimeofday(&now,NULL) < 0) - return -1; + my_gettimeofday(&now); + conn->timestamp_lastread = now.tv_sec; read_result = read_to_buf(conn->s, conn->receiver_bucket, &conn->inbuf, &conn->inbuflen, @@ -395,8 +369,7 @@ int connection_decompress_to_buf(char *string, int len, connection_t *conn, if (n < 0) return -1; - if(gettimeofday(&now,NULL) < 0) - return -1; + my_gettimeofday(&now,NULL); if(!n) return 0; @@ -430,8 +403,7 @@ int connection_flush_buf(connection_t *conn) { int connection_write_to_buf(char *string, int len, connection_t *conn) { struct timeval now; - if(gettimeofday(&now,NULL) < 0) - return -1; + my_gettimeofday(&now); if(!len) return 0; @@ -585,8 +557,7 @@ void connection_init_timeval(connection_t *conn) { assert(conn); - if(gettimeofday(&conn->send_timeval,NULL) < 0) - return; + my_gettimeofday(&conn->send_timeval); connection_increment_send_timeval(conn); } diff --git a/src/or/main.c b/src/or/main.c index 023836d4bf..e0341061eb 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -307,8 +307,7 @@ int prepare_for_poll(int *timeout) { cell_t cell; circuit_t *circ; - if(gettimeofday(&now,NULL) < 0) - return -1; + my_gettimeofday(&now); if(now.tv_sec > current_second) { /* the second has rolled over. check more stuff. */ @@ -535,8 +534,7 @@ void dumpstats(void) { /* dump stats to stdout */ extern char *conn_state_to_string[][15]; printf("Dumping stats:\n"); - if(gettimeofday(&now,NULL) < 0) - return ; + my_gettimeofday(&now); for(i=0;i<nfds;i++) { conn = connection_array[i]; diff --git a/src/or/or.h b/src/or/or.h index b0be6b91ea..5e84ec3b83 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -46,6 +46,7 @@ #include "../common/log.h" #include "../common/ss.h" #include "../common/version.h" +#include "../common/util.h" #define MAXCONNECTIONS 1000 /* upper bound on max connections. can be lowered by config file */ |