[or-cvs] Factor out timeval-related functions.
Nick Mathewson
nickm at seul.org
Wed Apr 16 17:05:01 UTC 2003
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv1720/src/or
Modified Files:
circuit.c command.c connection.c main.c or.h
Log Message:
Factor out timeval-related functions.
Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- circuit.c 16 Apr 2003 16:19:27 -0000 1.31
+++ circuit.c 16 Apr 2003 17:04:57 -0000 1.32
@@ -53,8 +53,7 @@
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 @@
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,18 +164,11 @@
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);
Index: command.c
===================================================================
RCS file: /home/or/cvsroot/src/or/command.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- command.c 7 Apr 2003 02:12:02 -0000 1.20
+++ command.c 16 Apr 2003 17:04:57 -0000 1.21
@@ -14,24 +14,14 @@
*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 @@
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 */
Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- connection.c 15 Apr 2003 19:10:18 -0000 1.53
+++ connection.c 16 Apr 2003 17:04:57 -0000 1.54
@@ -61,31 +61,6 @@
/********* 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 *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 @@
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 @@
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_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 @@
assert(conn);
- if(gettimeofday(&conn->send_timeval,NULL) < 0)
- return;
+ my_gettimeofday(&conn->send_timeval);
connection_increment_send_timeval(conn);
}
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- main.c 16 Apr 2003 06:18:30 -0000 1.48
+++ main.c 16 Apr 2003 17:04:58 -0000 1.49
@@ -307,8 +307,7 @@
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 @@
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];
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- or.h 16 Apr 2003 16:19:27 -0000 1.65
+++ or.h 16 Apr 2003 17:04:58 -0000 1.66
@@ -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 */
More information about the tor-commits
mailing list