From 9f58a2ece416c9d407b0895243fbbc1cfeef82ed Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Sat, 5 Jul 2003 05:46:06 +0000 Subject: clean up main.c a bit svn:r364 --- src/or/main.c | 126 +++++++++++++++++++++++++++++----------------------------- src/or/or.h | 12 +----- 2 files changed, 66 insertions(+), 72 deletions(-) (limited to 'src') diff --git a/src/or/main.c b/src/or/main.c index 0ee26e4b9d..f2a69fc471 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -4,6 +4,10 @@ #include "or.h" +/********* START PROTOTYPES **********/ + +static void dumpstats(void); /* dump stats to stdout */ + /********* START VARIABLES **********/ or_options_t options; /* command-line and config-file options */ @@ -233,83 +237,79 @@ void connection_start_writing(connection_t *conn) { } -void check_conn_read(int i) { +static void conn_read(int i) { int retval; connection_t *conn; - if(poll_array[i].revents & POLLIN) { /* something to read */ - - conn = connection_array[i]; - assert(conn); -// log(LOG_DEBUG,"check_conn_read(): socket %d has something to read.",conn->s); - - if (conn->type == CONN_TYPE_OR_LISTENER) { - retval = connection_or_handle_listener_read(conn); - } else if (conn->type == CONN_TYPE_AP_LISTENER) { - retval = connection_ap_handle_listener_read(conn); - } else if (conn->type == CONN_TYPE_DIR_LISTENER) { - retval = connection_dir_handle_listener_read(conn); - } else { - retval = connection_read_to_buf(conn); - if (retval < 0 && conn->type == CONN_TYPE_DIR && conn->state == DIR_CONN_STATE_CONNECTING) { - /* it's a directory server and connecting failed: forget about this router */ - router_forget_router(conn->addr,conn->port); /* FIXME i don't think this function works. */ - } - if (retval >= 0) { /* all still well */ - retval = connection_process_inbuf(conn); -// log(LOG_DEBUG,"check_conn_read(): connection_process_inbuf returned %d.",retval); - if(retval >= 0 && !connection_state_is_open(conn) && conn->receiver_bucket == 0) { - log(LOG_DEBUG,"check_conn_read(): receiver bucket reached 0 before handshake finished. Closing."); - retval = -1; - } + conn = connection_array[i]; + assert(conn); +// log_fn(LOG_DEBUG,"socket %d has something to read.",conn->s); + + if (conn->type == CONN_TYPE_OR_LISTENER) { + retval = connection_or_handle_listener_read(conn); + } else if (conn->type == CONN_TYPE_AP_LISTENER) { + retval = connection_ap_handle_listener_read(conn); + } else if (conn->type == CONN_TYPE_DIR_LISTENER) { + retval = connection_dir_handle_listener_read(conn); + } else { + retval = connection_read_to_buf(conn); + if (retval < 0 && conn->type == CONN_TYPE_DIR && conn->state == DIR_CONN_STATE_CONNECTING) { + /* it's a directory server and connecting failed: forget about this router */ + router_forget_router(conn->addr,conn->port); /* FIXME i don't think this function works. */ + } + if (retval >= 0) { /* all still well */ + retval = connection_process_inbuf(conn); +// log_fn(LOG_DEBUG,"connection_process_inbuf returned %d.",retval); + if(retval >= 0 && !connection_state_is_open(conn) && conn->receiver_bucket == 0) { + log(LOG_DEBUG,"conn_read(): receiver bucket reached 0 before handshake finished. Closing."); + retval = -1; } } + } - if(retval < 0) { /* this connection is broken. remove it */ - log(LOG_INFO,"check_conn_read(): Connection broken, removing."); - connection_remove(conn); - connection_free(conn); - if(is); - conn = connection_array[i]; -// log(LOG_DEBUG,"check_conn_write(): socket %d wants to write.",conn->s); - - if(connection_is_listener(conn)) { - log(LOG_DEBUG,"check_conn_write(): Got a listener socket. Can't happen!"); - retval = -1; - } else { - /* else it's an OP, OR, or exit */ - retval = connection_flush_buf(conn); /* conns in CONNECTING state will fall through... */ - if(retval == 0) { /* it's done flushing */ - retval = connection_finished_flushing(conn); /* ...and get handled here. */ - } + if(connection_is_listener(conn)) { + log_fn(LOG_DEBUG,"Got a listener socket. Can't happen!"); + retval = -1; + } else { + /* else it's an OP, OR, or exit */ + retval = connection_flush_buf(conn); /* conns in CONNECTING state will fall through... */ + if(retval == 0) { /* it's done flushing */ + retval = connection_finished_flushing(conn); /* ...and get handled here. */ } + } - if(retval < 0) { /* this connection is broken. remove it. */ - log(LOG_DEBUG,"check_conn_write(): Connection broken, removing."); - connection_remove(conn); - connection_free(conn); - if(i 0) { /* we have at least one connection to deal with */ /* do all the reads first, so we can detect closed sockets */ for(i=0;i