[or-cvs] Handle windows socket errors correctly; comment most of com...
Nick Mathewson
nickm at seul.org
Sat May 1 20:46:30 UTC 2004
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv4176/src/or
Modified Files:
buffers.c connection.c connection_edge.c connection_or.c
directory.c main.c test.c
Log Message:
Handle windows socket errors correctly; comment most of common.
Index: buffers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/buffers.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- buffers.c 28 Apr 2004 20:13:21 -0000 1.84
+++ buffers.c 1 May 2004 20:46:28 -0000 1.85
@@ -190,15 +190,9 @@
// 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 */
- return -1;
- }
-#ifdef MS_WINDOWS
- e = correct_socket_errno(s);
- if(!ERRNO_EAGAIN(e)) { /* no, it *is* a real error! */
+ if(!ERRNO_IS_EAGAIN(tor_socket_errno(s))) { /* it's a real error */
return -1;
}
-#endif
return 0;
} else if (read_result == 0) {
log_fn(LOG_DEBUG,"Encountered eof");
@@ -262,16 +256,11 @@
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 */
- return -1;
- }
-#ifdef MS_WINDOWS
- e = correct_socket_errno(s);
- if(!ERRNO_EAGAIN(e)) { /* no, it *is* a real error! */
+ 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;
}
-#endif
log_fn(LOG_DEBUG,"write() would block, returning.");
return 0;
} else {
Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.205
retrieving revision 1.206
diff -u -d -r1.205 -r1.206
--- connection.c 28 Apr 2004 21:14:56 -0000 1.205
+++ connection.c 1 May 2004 20:46:28 -0000 1.206
@@ -278,12 +278,14 @@
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 @@
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 @@
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 {
Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.180
retrieving revision 1.181
diff -u -d -r1.180 -r1.181
--- connection_edge.c 28 Apr 2004 21:14:56 -0000 1.180
+++ connection_edge.c 1 May 2004 20:46:28 -0000 1.181
@@ -479,7 +479,7 @@
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);
Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -d -r1.99 -r1.100
--- connection_or.c 25 Apr 2004 20:37:37 -0000 1.99
+++ connection_or.c 1 May 2004 20:46:28 -0000 1.100
@@ -49,7 +49,7 @@
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;
Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -d -r1.93 -r1.94
--- directory.c 27 Apr 2004 21:48:37 -0000 1.93
+++ directory.c 1 May 2004 20:46:28 -0000 1.94
@@ -480,7 +480,7 @@
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);
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.251
retrieving revision 1.252
diff -u -d -r1.251 -r1.252
--- main.c 26 Apr 2004 09:32:51 -0000 1.251
+++ main.c 1 May 2004 20:46:28 -0000 1.252
@@ -653,8 +653,10 @@
/* 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.");
Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- test.c 28 Apr 2004 20:31:32 -0000 1.85
+++ test.c 1 May 2004 20:46:28 -0000 1.86
@@ -205,29 +205,29 @@
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);
+ test_eq(crypto_dh_get_bytes(dh1), DH_BYTES);
+ test_eq(crypto_dh_get_bytes(dh2), DH_BYTES);
- 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(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, 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);
+ 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);
More information about the tor-commits
mailing list