summaryrefslogtreecommitdiff
path: root/src/or/connection.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-05-05 01:26:57 +0000
committerNick Mathewson <nickm@torproject.org>2004-05-05 01:26:57 +0000
commit2ba0776b027db8fa619b61fb074bf2400ac18728 (patch)
tree2f217a760e380760ac2f6efd1f4b5a0c35327a92 /src/or/connection.c
parentd49d3dcc7bc19e9b9fb2aa29f7d94379a8aedf52 (diff)
downloadtor-2ba0776b027db8fa619b61fb074bf2400ac18728.tar.gz
tor-2ba0776b027db8fa619b61fb074bf2400ac18728.zip
Only connection_add connections once they have conn->s sett; refactor code around this. Should make stuff more bulletproof.
svn:r1788
Diffstat (limited to 'src/or/connection.c')
-rw-r--r--src/or/connection.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index 9b3100e0f4..c163cd8636 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -365,10 +365,11 @@ static int connection_init_accepted_conn(connection_t *conn) {
return 0;
}
-/* take conn, make a nonblocking socket; try to connect to
+/* Take conn, make a nonblocking socket; try to connect to
* addr:port (they arrive in *host order*). If fail, return -1. Else
* assign s to conn->s: if connected return 1, if eagain return 0.
- * address is used to make the logs useful.
+ * address is used to make the logs useful. On success, add 'conn' to
+ * the list of polled connections.
*/
int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_t port) {
int s;
@@ -398,6 +399,8 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_
} else {
/* it's in progress. set state appropriately and return. */
conn->s = s;
+ if(connection_add(conn) < 0) /* no space, forget it */
+ return -1;
log_fn(LOG_DEBUG,"connect in progress, socket %d.",s);
return 0;
}
@@ -406,6 +409,8 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_
/* it succeeded. we're connected. */
log_fn(LOG_INFO,"Connection to %s:%u established.",address,port);
conn->s = s;
+ if(connection_add(conn) < 0) /* no space, forget it */
+ return -1;
return 1;
}