diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-05-12 19:17:09 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-05-12 19:17:09 +0000 |
commit | f1bc7af9f54bb4b563ffa024b1e32a6acacef26f (patch) | |
tree | 45bfe6288f7d804617795d79fd48049726e6dada /src/or/connection_or.c | |
parent | 4c9138d6406285077c3fc527f181610cd81b5727 (diff) | |
download | tor-f1bc7af9f54bb4b563ffa024b1e32a6acacef26f.tar.gz tor-f1bc7af9f54bb4b563ffa024b1e32a6acacef26f.zip |
Make "connected" a different case from "finished_flushing"; always close_immediate whhen connect() fails.
svn:r1852
Diffstat (limited to 'src/or/connection_or.c')
-rw-r--r-- | src/or/connection_or.c | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 466024054f..a2582743bc 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -59,50 +59,41 @@ int connection_or_process_inbuf(connection_t *conn) { /** Connection <b>conn</b> has finished writing and has no bytes left on * its outbuf. * - * If it's in state "connecting", then take a look at the socket, and - * begin the tls handshake if the connect succeeded. - * * Otherwise it's in state "open": stop writing and return. * * If <b>conn</b> is broken, mark it for close and return -1, else * return 0. */ int connection_or_finished_flushing(connection_t *conn) { - int e, len=sizeof(e); - tor_assert(conn && conn->type == CONN_TYPE_OR); + assert_connection_ok(conn,0); - switch(conn->state) { - case OR_CONN_STATE_CONNECTING: - if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0) { - /* not yet */ - 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; - } else { - return 0; /* no change, see if next time is better */ - } - } - /* the connect has finished. */ - - log_fn(LOG_INFO,"OR connect() to router %s:%u finished.", - conn->address,conn->port); - - if(connection_tls_start_handshake(conn, 0) < 0) { - /* TLS handhaking error of some kind. */ - connection_mark_for_close(conn,0); - return -1; - } - return 0; - case OR_CONN_STATE_OPEN: - connection_stop_writing(conn); - return 0; - default: - log_fn(LOG_WARN,"BUG: called in unexpected state %d",conn->state); - return 0; + if (conn->state != OR_CONN_STATE_OPEN) { + log_fn(LOG_WARN,"BUG: called in unexpected state %d",conn->state); + return -1; } + + connection_stop_writing(conn); + return 0; +} + +/** Connected handler for OR connections: begin the TLS handshake. + */ +int connection_or_finished_connecting(connection_t *conn) +{ + tor_assert(conn && conn->type == CONN_TYPE_OR); + tor_assert(conn->state == OR_CONN_STATE_CONNECTING); + + log_fn(LOG_INFO,"OR connect() to router %s:%u finished.", + conn->address,conn->port); + + if(connection_tls_start_handshake(conn, 0) < 0) { + /* TLS handhaking error of some kind. */ + connection_mark_for_close(conn,0); + return -1; + } + return 0; } /** Initialize <b>conn</b> to include all the relevant data from <b>router</b>. |