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/connection.c | |
parent | 0c61bc3756e833abe97999fa2a22b944a9ce3931 (diff) | |
download | tor-33176c70a5b9bb345d96af22178c003e177b2bb9.tar tor-33176c70a5b9bb345d96af22178c003e177b2bb9.tar.gz |
Factor out timeval-related functions.
svn:r237
Diffstat (limited to 'src/or/connection.c')
-rw-r--r-- | src/or/connection.c | 41 |
1 files changed, 6 insertions, 35 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index 20b29dfa2..c15eb0010 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); } |