diff options
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/buffers.c | 19 | ||||
-rw-r--r-- | src/or/connection.c | 19 | ||||
-rw-r--r-- | src/or/connection_edge.c | 2 | ||||
-rw-r--r-- | src/or/connection_or.c | 2 | ||||
-rw-r--r-- | src/or/directory.c | 2 | ||||
-rw-r--r-- | src/or/main.c | 6 | ||||
-rw-r--r-- | src/or/test.c | 38 |
7 files changed, 38 insertions, 50 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 6598c2654c..931a83b0ff 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -190,15 +190,9 @@ int read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof) { // log_fn(LOG_DEBUG,"reading at most %d bytes.",at_most); read_result = recv(s, buf->mem+buf->datalen, at_most, 0); if (read_result < 0) { - if(!ERRNO_EAGAIN(errno)) { /* it's a real error */ + if(!ERRNO_IS_EAGAIN(tor_socket_errno(s))) { /* it's a real error */ return -1; } -#ifdef MS_WINDOWS - e = correct_socket_errno(s); - if(!ERRNO_EAGAIN(e)) { /* no, it *is* a real error! */ - return -1; - } -#endif return 0; } else if (read_result == 0) { log_fn(LOG_DEBUG,"Encountered eof"); @@ -262,16 +256,11 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen) write_result = send(s, buf->mem, *buf_flushlen, 0); if (write_result < 0) { - if(!ERRNO_EAGAIN(errno)) { /* it's a real error */ - tor_assert(errno != EPIPE); /* get a stack trace to find epipe bugs */ + if(!ERRNO_IS_EAGAIN(tor_socket_errno(s))) { /* it's a real error */ + /* get a stack trace to find epipe bugs */ + tor_assert(tor_socket_errno(s) != EPIPE); return -1; } -#ifdef MS_WINDOWS - e = correct_socket_errno(s); - if(!ERRNO_EAGAIN(e)) { /* no, it *is* a real error! */ - return -1; - } -#endif log_fn(LOG_DEBUG,"write() would block, returning."); return 0; } else { diff --git a/src/or/connection.c b/src/or/connection.c index 1b1f4c4b15..690f442618 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -278,12 +278,14 @@ int connection_create_listener(char *bindaddress, uint16_t bindport, int type) { setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*) &one, sizeof(one)); if(bind(s,(struct sockaddr *)&bindaddr,sizeof(bindaddr)) < 0) { - log_fn(LOG_WARN,"Could not bind to port %u: %s",bindport,strerror(errno)); + log_fn(LOG_WARN,"Could not bind to port %u: %s",bindport, + strerror(tor_socket_errno())); return -1; } if(listen(s,SOMAXCONN) < 0) { - log_fn(LOG_WARN,"Could not listen on port %u: %s",bindport,strerror(errno)); + log_fn(LOG_WARN,"Could not listen on port %u: %s",bindport, + strerror(tor_socket_errno())); return -1; } @@ -317,14 +319,8 @@ static int connection_handle_listener_read(connection_t *conn, int new_type) { news = accept(conn->s,(struct sockaddr *)&remote,&remotelen); if (news == -1) { /* accept() error */ - if(ERRNO_EAGAIN(errno)) { -#ifdef MS_WINDOWS - e = correct_socket_errno(conn->s); - if (ERRNO_EAGAIN(e)) - return 0; -#else + if(ERRNO_IS_EAGAIN(tor_socket_errno(conn->s))) { return 0; /* he hung up before we could accept(). that's fine. */ -#endif } /* else there was a real error. */ log_fn(LOG_WARN,"accept() failed. Closing listener."); @@ -396,9 +392,10 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_ log_fn(LOG_DEBUG,"Connecting to %s:%u.",address,port); if(connect(s,(struct sockaddr *)&dest_addr,sizeof(dest_addr)) < 0) { - if(!ERRNO_CONN_EINPROGRESS(errno)) { + if(!ERRNO_IS_CONN_EINPROGRESS(tor_socket_errno(s))) { /* yuck. kill it. */ - log_fn(LOG_INFO,"Connect() to %s:%u failed: %s",address,port,strerror(errno)); + log_fn(LOG_INFO,"Connect() to %s:%u failed: %s",address,port, + strerror(tor_socket_errno(s))); tor_close_socket(s); return -1; } else { diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 365b39ad97..7a9bdfd0a3 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -479,7 +479,7 @@ int connection_edge_finished_flushing(connection_t *conn) { switch(conn->state) { case EXIT_CONN_STATE_CONNECTING: if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0) { /* not yet */ - if(!ERRNO_CONN_EINPROGRESS(errno)) { + if(!ERRNO_IS_CONN_EINPROGRESS(tor_socket_errno(conn->s))) { /* yuck. kill it. */ log_fn(LOG_DEBUG,"in-progress exit connect failed. Removing."); connection_mark_for_close(conn, END_STREAM_REASON_CONNECTFAILED); diff --git a/src/or/connection_or.c b/src/or/connection_or.c index bb6eb1367e..02ee368a01 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -49,7 +49,7 @@ int connection_or_finished_flushing(connection_t *conn) { switch(conn->state) { case OR_CONN_STATE_CONNECTING: if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0) { /* not yet */ - if(!ERRNO_CONN_EINPROGRESS(errno)){ + if(!ERRNO_IS_CONN_EINPROGRESS(tor_socket_errno(conn->s))) { log_fn(LOG_DEBUG,"in-progress connect failed. Removing."); connection_mark_for_close(conn,0); return -1; diff --git a/src/or/directory.c b/src/or/directory.c index 1c8fa059a0..9c6722390a 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -480,7 +480,7 @@ int connection_dir_finished_flushing(connection_t *conn) { switch(conn->state) { case DIR_CONN_STATE_CONNECTING: if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0) { /* not yet */ - if(!ERRNO_CONN_EINPROGRESS(errno)) { + if(!ERRNO_IS_CONN_EINPROGRESS(tor_socket_errno(conn->s))) { log_fn(LOG_DEBUG,"in-progress connect failed. Removing."); router_mark_as_down(conn->nickname); /* don't try him again */ connection_mark_for_close(conn,0); diff --git a/src/or/main.c b/src/or/main.c index 83dc87dfe8..836f4d665b 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -653,8 +653,10 @@ static int do_main_loop(void) { /* let catch() handle things like ^c, and otherwise don't worry about it */ if(poll_result < 0) { - if(errno != EINTR) { /* let the program survive things like ^z */ - log_fn(LOG_ERR,"poll failed: %s",strerror(errno)); + /* let the program survive things like ^z */ + if(tor_socket_errno(-1) != EINTR) { + log_fn(LOG_ERR,"poll failed: %s [%d]", + strerror(tor_socket_errno(-1)), tor_socket_errno(-1)); return -1; } else { log_fn(LOG_DEBUG,"poll interrupted."); diff --git a/src/or/test.c b/src/or/test.c index 536511949d..6e37ba1435 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -205,29 +205,29 @@ void test_crypto_dh() { crypto_dh_env_t *dh1, *dh2; - char p1[CRYPTO_DH_SIZE]; - char p2[CRYPTO_DH_SIZE]; - char s1[CRYPTO_DH_SIZE]; - char s2[CRYPTO_DH_SIZE]; + char p1[DH_BYTES]; + char p2[DH_BYTES]; + char s1[DH_BYTES]; + char s2[DH_BYTES]; int s1len, s2len; dh1 = crypto_dh_new(); dh2 = crypto_dh_new(); - test_eq(crypto_dh_get_bytes(dh1), CRYPTO_DH_SIZE); - test_eq(crypto_dh_get_bytes(dh2), CRYPTO_DH_SIZE); - - memset(p1, 0, CRYPTO_DH_SIZE); - memset(p2, 0, CRYPTO_DH_SIZE); - test_memeq(p1, p2, CRYPTO_DH_SIZE); - test_assert(! crypto_dh_get_public(dh1, p1, CRYPTO_DH_SIZE)); - test_memneq(p1, p2, CRYPTO_DH_SIZE); - test_assert(! crypto_dh_get_public(dh2, p2, CRYPTO_DH_SIZE)); - test_memneq(p1, p2, CRYPTO_DH_SIZE); - - memset(s1, 0, CRYPTO_DH_SIZE); - memset(s2, 0xFF, CRYPTO_DH_SIZE); - s1len = crypto_dh_compute_secret(dh1, p2, CRYPTO_DH_SIZE, s1, 50); - s2len = crypto_dh_compute_secret(dh2, p1, CRYPTO_DH_SIZE, s2, 50); + test_eq(crypto_dh_get_bytes(dh1), DH_BYTES); + test_eq(crypto_dh_get_bytes(dh2), DH_BYTES); + + memset(p1, 0, DH_BYTES); + memset(p2, 0, DH_BYTES); + test_memeq(p1, p2, DH_BYTES); + test_assert(! crypto_dh_get_public(dh1, p1, DH_BYTES)); + test_memneq(p1, p2, DH_BYTES); + test_assert(! crypto_dh_get_public(dh2, p2, DH_BYTES)); + test_memneq(p1, p2, DH_BYTES); + + memset(s1, 0, DH_BYTES); + memset(s2, 0xFF, DH_BYTES); + s1len = crypto_dh_compute_secret(dh1, p2, DH_BYTES, s1, 50); + s2len = crypto_dh_compute_secret(dh2, p1, DH_BYTES, s2, 50); test_assert(s1len > 0); test_eq(s1len, s2len); test_memeq(s1, s2, s1len); |