diff options
author | Roger Dingledine <arma@torproject.org> | 2007-04-25 07:20:04 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2007-04-25 07:20:04 +0000 |
commit | 3d00738ec72e87d5d67f1c44f0a73217650a6a65 (patch) | |
tree | 1373aef4297bfb8cf22ce3c98c7f0386f30458ea /src/or | |
parent | 7c5f65c2267e243dfc8bea9c899e8f04a078ca36 (diff) | |
download | tor-3d00738ec72e87d5d67f1c44f0a73217650a6a65.tar.gz tor-3d00738ec72e87d5d67f1c44f0a73217650a6a65.zip |
simplify connection_watch_events()
hope this doesn't break it
svn:r10025
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/buffers.c | 3 | ||||
-rw-r--r-- | src/or/main.c | 60 |
2 files changed, 14 insertions, 49 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 26a5b9683c..6273c6699b 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -884,7 +884,8 @@ fetch_from_buf(char *string, size_t string_len, buf_t *buf) return buf->datalen; } -/** Move up to <b>buf_flushlen</b> bytes from <b>buf_in</b> to <b>buf_out</b>. +/** Move up to *<b>buf_flushlen</b> bytes from <b>buf_in</b> to + * <b>buf_out</b>, and modify *<b>buf_flushlen</b> appropriately. * Return the number of bytes actually copied. */ int diff --git a/src/or/main.c b/src/or/main.c index 0edbd12ad7..fa6f353a2a 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -162,7 +162,7 @@ connection_add(connection_t *conn) tor_assert(conn->s >= 0 || conn->linked); tor_assert(conn->conn_array_index == -1); /* can only connection_add once */ - if (n_conns == MAXCONNECTIONS) { + if (n_conns >= MAXCONNECTIONS) { log_warn(LD_BUG, "Unable to add a connection; MAXCONNECTIONS is set too " "low. This is a bug; tell the developers."); return -1; @@ -297,51 +297,15 @@ get_connection_array(connection_t ***array, int *n) void connection_watch_events(connection_t *conn, short events) { - int r = 0; - - tor_assert(conn); - tor_assert(conn->read_event); - tor_assert(conn->write_event); - - if (conn->linked) { - if (events & EV_READ) - connection_start_reading(conn); - else - connection_stop_reading(conn); - } else { - if (events & EV_READ) { - r = event_add(conn->read_event, NULL); - } else { - r = event_del(conn->read_event); - } - } - - if (r<0) - log_warn(LD_NET, - "Error from libevent setting read event state for %d to " - "%swatched: %s", - conn->s, (events & EV_READ)?"":"un", - tor_socket_strerror(tor_socket_errno(conn->s))); - - if (conn->linked) { - if (events & EV_WRITE) - connection_start_writing(conn); - else - connection_stop_writing(conn); - } else { - if (events & EV_WRITE) { - r = event_add(conn->write_event, NULL); - } else { - r = event_del(conn->write_event); - } - } + if (events & EV_READ) + connection_start_reading(conn); + else + connection_stop_reading(conn); - if (r<0) - log_warn(LD_NET, - "Error from libevent setting read event state for %d to " - "%swatched: %s", - conn->s, (events & EV_WRITE)?"":"un", - tor_socket_strerror(tor_socket_errno(conn->s))); + if (events & EV_WRITE) + connection_start_writing(conn); + else + connection_stop_writing(conn); } /** Return true iff <b>conn</b> is listening for read events. */ @@ -458,7 +422,7 @@ connection_start_reading_from_linked_conn(connection_t *conn) /* This is the first event on the list; we won't be in LOOP_ONCE mode, * so we need to make sure that the event_loop() actually exits at the * end of its run through the current connections and - * lets us activate read events for linked connections. */ + * lets us activate read events for linked connections. */ struct timeval tv = { 0, 0 }; event_loopexit(&tv); } @@ -484,7 +448,7 @@ connection_stop_reading_from_linked_conn(connection_t *conn) } } -/** Close all connections that have been scheduled to get closed */ +/** Close all connections that have been scheduled to get closed. */ static void close_closeable_connections(void) { @@ -1380,7 +1344,7 @@ do_main_loop(void) called_loop_once = smartlist_len(active_linked_connection_lst) ? 1 : 0; /* poll until we have an event, or the second ends, or until we have - * some active linked connections to triggger events for. */ + * some active linked connections to trigger events for. */ loop_result = event_loop(called_loop_once ? EVLOOP_ONCE : 0); /* let catch() handle things like ^c, and otherwise don't worry about it */ |