[or-cvs] clean up main.c a bit
Roger Dingledine
arma at seul.org
Sat Jul 5 05:46:08 UTC 2003
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or
Modified Files:
main.c or.h
Log Message:
clean up main.c a bit
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- main.c 26 Jun 2003 23:38:21 -0000 1.75
+++ main.c 5 Jul 2003 05:46:05 -0000 1.76
@@ -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 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);
+ 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(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;
- }
+ 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(i<nfds) { /* we just replaced the one at i with a new one.
- process it too. */
- check_conn_read(i);
- }
+ if(retval < 0) { /* this connection is broken. remove it */
+ log_fn(LOG_INFO,"Connection broken, removing.");
+ connection_remove(conn);
+ connection_free(conn);
+ if(i<nfds) { /* we just replaced the one at i with a new one.
+ process it too. */
+ if(poll_array[i].revents & POLLIN) /* something to read */
+ conn_read(i);
}
}
}
-void check_conn_write(int i) {
+static void conn_write(int i) {
int retval;
connection_t *conn;
- if(poll_array[i].revents & POLLOUT) { /* something to write */
-
- conn = connection_array[i];
-// log(LOG_DEBUG,"check_conn_write(): socket %d wants to write.",conn->s);
+ conn = connection_array[i];
+// log_fn(LOG_DEBUG,"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<nfds) { /* we just replaced the one at i with a new one.
- process it too. */
- check_conn_write(i);
- }
+ if(retval < 0) { /* this connection is broken. remove it. */
+ log_fn(LOG_DEBUG,"Connection broken, removing.");
+ connection_remove(conn);
+ connection_free(conn);
+ if(i<nfds) { /* we just replaced the one at i with a new one.
+ process it too. */
+ if(poll_array[i].revents & POLLOUT) /* something to write */
+ conn_write(i);
}
}
}
-void check_conn_marked(int i) {
+static void check_conn_marked(int i) {
connection_t *conn;
conn = connection_array[i];
@@ -329,7 +329,7 @@
}
}
-int prepare_for_poll(int *timeout) {
+static int prepare_for_poll(int *timeout) {
int i;
// connection_t *conn = NULL;
connection_t *tmpconn;
@@ -446,7 +446,7 @@
}
#endif
-int do_main_loop(void) {
+static int do_main_loop(void) {
int i;
int timeout;
int poll_result;
@@ -536,11 +536,13 @@
if(poll_result > 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<nfds;i++)
- check_conn_read(i); /* this also blows away broken connections */
+ if(poll_array[i].revents & POLLIN) /* something to read */
+ conn_read(i); /* this also blows away broken connections */
/* then do the writes */
for(i=0;i<nfds;i++)
- check_conn_write(i);
+ if(poll_array[i].revents & POLLOUT) /* something to write */
+ conn_write(i);
/* any of the conns need to be closed now? */
for(i=0;i<nfds;i++)
@@ -571,7 +573,7 @@
}
}
-void dumpstats(void) { /* dump stats to stdout */
+static void dumpstats(void) { /* dump stats to stdout */
int i;
connection_t *conn;
struct timeval now;
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -d -r1.96 -r1.97
--- or.h 27 Jun 2003 00:57:04 -0000 1.96
+++ or.h 5 Jul 2003 05:46:06 -0000 1.97
@@ -205,8 +205,9 @@
/* Used by all types: */
- unsigned char type;
+ uint8_t type;
int state;
+ uint8_t wants_to_read;
int s; /* our socket */
int poll_index;
int marked_for_close;
@@ -665,15 +666,6 @@
void connection_stop_writing(connection_t *conn);
void connection_start_writing(connection_t *conn);
-void check_conn_read(int i);
-void check_conn_marked(int i);
-void check_conn_write(int i);
-
-int prepare_for_poll(int *timeout);
-
-int do_main_loop(void);
-
-void dumpstats(void);
int dump_signed_directory_to_string(char *s, int maxlen,
crypto_pk_env_t *private_key);
/* Exported for debugging */
More information about the tor-commits
mailing list