mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
clean up main.c a bit
svn:r364
This commit is contained in:
parent
75440d08c2
commit
9f58a2ece4
@ -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,15 +237,13 @@ 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);
|
||||
// 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);
|
||||
@ -257,37 +259,35 @@ void check_conn_read(int i) {
|
||||
}
|
||||
if (retval >= 0) { /* all still well */
|
||||
retval = connection_process_inbuf(conn);
|
||||
// log(LOG_DEBUG,"check_conn_read(): connection_process_inbuf returned %d.",retval);
|
||||
// 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,"check_conn_read(): receiver bucket reached 0 before handshake finished. Closing.");
|
||||
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.");
|
||||
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. */
|
||||
check_conn_read(i);
|
||||
}
|
||||
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);
|
||||
// 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!");
|
||||
log_fn(LOG_DEBUG,"Got a listener socket. Can't happen!");
|
||||
retval = -1;
|
||||
} else {
|
||||
/* else it's an OP, OR, or exit */
|
||||
@ -298,18 +298,18 @@ void check_conn_write(int i) {
|
||||
}
|
||||
|
||||
if(retval < 0) { /* this connection is broken. remove it. */
|
||||
log(LOG_DEBUG,"check_conn_write(): Connection broken, removing.");
|
||||
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. */
|
||||
check_conn_write(i);
|
||||
}
|
||||
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 @@ void check_conn_marked(int i) {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ int prepare_for_poll(int *timeout) {
|
||||
}
|
||||
#endif
|
||||
|
||||
int do_main_loop(void) {
|
||||
static int do_main_loop(void) {
|
||||
int i;
|
||||
int timeout;
|
||||
int poll_result;
|
||||
@ -536,11 +536,13 @@ int do_main_loop(void) {
|
||||
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 @@ static void catch(int the_signal) {
|
||||
}
|
||||
}
|
||||
|
||||
void dumpstats(void) { /* dump stats to stdout */
|
||||
static void dumpstats(void) { /* dump stats to stdout */
|
||||
int i;
|
||||
connection_t *conn;
|
||||
struct timeval now;
|
||||
|
12
src/or/or.h
12
src/or/or.h
@ -205,8 +205,9 @@ struct connection_t {
|
||||
|
||||
/* 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_start_reading(connection_t *conn);
|
||||
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 */
|
||||
|
Loading…
Reference in New Issue
Block a user