|
@@ -68,8 +68,8 @@ void evdns_shutdown(int);
|
|
|
|
|
|
static void dumpmemusage(int severity);
|
|
|
static void dumpstats(int severity); /* log stats */
|
|
|
-static void conn_read_callback(int fd, short event, void *_conn);
|
|
|
-static void conn_write_callback(int fd, short event, void *_conn);
|
|
|
+static void conn_read_callback(evutil_socket_t fd, short event, void *_conn);
|
|
|
+static void conn_write_callback(evutil_socket_t fd, short event, void *_conn);
|
|
|
static void second_elapsed_callback(periodic_timer_t *timer, void *args);
|
|
|
static int conn_close_if_marked(int i);
|
|
|
static void connection_start_reading_from_linked_conn(connection_t *conn);
|
|
@@ -195,7 +195,7 @@ int
|
|
|
connection_add_impl(connection_t *conn, int is_connecting)
|
|
|
{
|
|
|
tor_assert(conn);
|
|
|
- tor_assert(conn->s >= 0 ||
|
|
|
+ tor_assert(SOCKET_OK(conn->s) ||
|
|
|
conn->linked ||
|
|
|
(conn->type == CONN_TYPE_AP &&
|
|
|
TO_EDGE_CONN(conn)->is_dns_request));
|
|
@@ -206,7 +206,7 @@ connection_add_impl(connection_t *conn, int is_connecting)
|
|
|
|
|
|
#ifdef USE_BUFFEREVENTS
|
|
|
if (connection_type_uses_bufferevent(conn)) {
|
|
|
- if (conn->s >= 0 && !conn->linked) {
|
|
|
+ if (SOCKET_OK(conn->s) && !conn->linked) {
|
|
|
conn->bufev = bufferevent_socket_new(
|
|
|
tor_libevent_get_base(),
|
|
|
conn->s,
|
|
@@ -225,7 +225,7 @@ connection_add_impl(connection_t *conn, int is_connecting)
|
|
|
connection_configure_bufferevent_callbacks(conn);
|
|
|
} else if (conn->linked && conn->linked_conn &&
|
|
|
connection_type_uses_bufferevent(conn->linked_conn)) {
|
|
|
- tor_assert(conn->s < 0);
|
|
|
+ tor_assert(!(SOCKET_OK(conn->s));
|
|
|
if (!conn->bufev) {
|
|
|
struct bufferevent *pair[2] = { NULL, NULL };
|
|
|
if (bufferevent_pair_new(tor_libevent_get_base(),
|
|
@@ -255,7 +255,7 @@ connection_add_impl(connection_t *conn, int is_connecting)
|
|
|
(void) is_connecting;
|
|
|
#endif
|
|
|
|
|
|
- if (!HAS_BUFFEREVENT(conn) && (conn->s >= 0 || conn->linked)) {
|
|
|
+ if (!HAS_BUFFEREVENT(conn) && (SOCKET_OK(conn->s) || conn->linked)) {
|
|
|
conn->read_event = tor_event_new(tor_libevent_get_base(),
|
|
|
conn->s, EV_READ|EV_PERSIST, conn_read_callback, conn);
|
|
|
conn->write_event = tor_event_new(tor_libevent_get_base(),
|
|
@@ -264,7 +264,7 @@ connection_add_impl(connection_t *conn, int is_connecting)
|
|
|
}
|
|
|
|
|
|
log_debug(LD_NET,"new conn type %s, socket %d, address %s, n_conns %d.",
|
|
|
- conn_type_to_string(conn->type), conn->s, conn->address,
|
|
|
+ conn_type_to_string(conn->type), (int)conn->s, conn->address,
|
|
|
smartlist_len(connection_array));
|
|
|
|
|
|
return 0;
|
|
@@ -276,12 +276,12 @@ connection_unregister_events(connection_t *conn)
|
|
|
{
|
|
|
if (conn->read_event) {
|
|
|
if (event_del(conn->read_event))
|
|
|
- log_warn(LD_BUG, "Error removing read event for %d", conn->s);
|
|
|
+ log_warn(LD_BUG, "Error removing read event for %d", (int)conn->s);
|
|
|
tor_free(conn->read_event);
|
|
|
}
|
|
|
if (conn->write_event) {
|
|
|
if (event_del(conn->write_event))
|
|
|
- log_warn(LD_BUG, "Error removing write event for %d", conn->s);
|
|
|
+ log_warn(LD_BUG, "Error removing write event for %d", (int)conn->s);
|
|
|
tor_free(conn->write_event);
|
|
|
}
|
|
|
#ifdef USE_BUFFEREVENTS
|
|
@@ -308,7 +308,7 @@ connection_remove(connection_t *conn)
|
|
|
tor_assert(conn);
|
|
|
|
|
|
log_debug(LD_NET,"removing socket %d (type %s), n_conns now %d",
|
|
|
- conn->s, conn_type_to_string(conn->type),
|
|
|
+ (int)conn->s, conn_type_to_string(conn->type),
|
|
|
smartlist_len(connection_array));
|
|
|
|
|
|
tor_assert(conn->conn_array_index >= 0);
|
|
@@ -473,7 +473,7 @@ connection_stop_reading(connection_t *conn)
|
|
|
if (event_del(conn->read_event))
|
|
|
log_warn(LD_NET, "Error from libevent setting read event state for %d "
|
|
|
"to unwatched: %s",
|
|
|
- conn->s,
|
|
|
+ (int)conn->s,
|
|
|
tor_socket_strerror(tor_socket_errno(conn->s)));
|
|
|
}
|
|
|
}
|
|
@@ -499,7 +499,7 @@ connection_start_reading(connection_t *conn)
|
|
|
if (event_add(conn->read_event, NULL))
|
|
|
log_warn(LD_NET, "Error from libevent setting read event state for %d "
|
|
|
"to watched: %s",
|
|
|
- conn->s,
|
|
|
+ (int)conn->s,
|
|
|
tor_socket_strerror(tor_socket_errno(conn->s)));
|
|
|
}
|
|
|
}
|
|
@@ -539,7 +539,7 @@ connection_stop_writing(connection_t *conn)
|
|
|
if (event_del(conn->write_event))
|
|
|
log_warn(LD_NET, "Error from libevent setting write event state for %d "
|
|
|
"to unwatched: %s",
|
|
|
- conn->s,
|
|
|
+ (int)conn->s,
|
|
|
tor_socket_strerror(tor_socket_errno(conn->s)));
|
|
|
}
|
|
|
}
|
|
@@ -566,7 +566,7 @@ connection_start_writing(connection_t *conn)
|
|
|
if (event_add(conn->write_event, NULL))
|
|
|
log_warn(LD_NET, "Error from libevent setting write event state for %d "
|
|
|
"to watched: %s",
|
|
|
- conn->s,
|
|
|
+ (int)conn->s,
|
|
|
tor_socket_strerror(tor_socket_errno(conn->s)));
|
|
|
}
|
|
|
}
|
|
@@ -652,13 +652,13 @@ close_closeable_connections(void)
|
|
|
/** Libevent callback: this gets invoked when (connection_t*)<b>conn</b> has
|
|
|
* some data to read. */
|
|
|
static void
|
|
|
-conn_read_callback(int fd, short event, void *_conn)
|
|
|
+conn_read_callback(evutil_socket_t fd, short event, void *_conn)
|
|
|
{
|
|
|
connection_t *conn = _conn;
|
|
|
(void)fd;
|
|
|
(void)event;
|
|
|
|
|
|
- log_debug(LD_NET,"socket %d wants to read.",conn->s);
|
|
|
+ log_debug(LD_NET,"socket %d wants to read.",(int)conn->s);
|
|
|
|
|
|
/* assert_connection_ok(conn, time(NULL)); */
|
|
|
|
|
@@ -667,7 +667,7 @@ conn_read_callback(int fd, short event, void *_conn)
|
|
|
#ifndef MS_WINDOWS
|
|
|
log_warn(LD_BUG,"Unhandled error on read for %s connection "
|
|
|
"(fd %d); removing",
|
|
|
- conn_type_to_string(conn->type), conn->s);
|
|
|
+ conn_type_to_string(conn->type), (int)conn->s);
|
|
|
tor_fragile_assert();
|
|
|
#endif
|
|
|
if (CONN_IS_EDGE(conn))
|
|
@@ -684,13 +684,14 @@ conn_read_callback(int fd, short event, void *_conn)
|
|
|
/** Libevent callback: this gets invoked when (connection_t*)<b>conn</b> has
|
|
|
* some data to write. */
|
|
|
static void
|
|
|
-conn_write_callback(int fd, short events, void *_conn)
|
|
|
+conn_write_callback(evutil_socket_t fd, short events, void *_conn)
|
|
|
{
|
|
|
connection_t *conn = _conn;
|
|
|
(void)fd;
|
|
|
(void)events;
|
|
|
|
|
|
- LOG_FN_CONN(conn, (LOG_DEBUG, LD_NET, "socket %d wants to write.",conn->s));
|
|
|
+ LOG_FN_CONN(conn, (LOG_DEBUG, LD_NET, "socket %d wants to write.",
|
|
|
+ (int)conn->s));
|
|
|
|
|
|
/* assert_connection_ok(conn, time(NULL)); */
|
|
|
|
|
@@ -699,7 +700,7 @@ conn_write_callback(int fd, short events, void *_conn)
|
|
|
/* this connection is broken. remove it. */
|
|
|
log_fn(LOG_WARN,LD_BUG,
|
|
|
"unhandled error on write for %s connection (fd %d); removing",
|
|
|
- conn_type_to_string(conn->type), conn->s);
|
|
|
+ conn_type_to_string(conn->type), (int)conn->s);
|
|
|
tor_fragile_assert();
|
|
|
if (CONN_IS_EDGE(conn)) {
|
|
|
/* otherwise we cry wolf about duplicate close */
|
|
@@ -757,7 +758,8 @@ conn_close_if_marked(int i)
|
|
|
|
|
|
log_debug(LD_NET,"Cleaning up connection (fd %d).",conn->s);
|
|
|
IF_HAS_BUFFEREVENT(conn, goto unlink);
|
|
|
- if ((conn->s >= 0 || conn->linked_conn) && connection_wants_to_flush(conn)) {
|
|
|
+ if ((SOCKET_OK(conn->s) || conn->linked_conn) &&
|
|
|
+ connection_wants_to_flush(conn)) {
|
|
|
/* s == -1 means it's an incomplete edge connection, or that the socket
|
|
|
* has already been closed as unflushable. */
|
|
|
ssize_t sz = connection_bucket_write_limit(conn, now);
|
|
@@ -766,7 +768,7 @@ conn_close_if_marked(int i)
|
|
|
"Conn (addr %s, fd %d, type %s, state %d) marked, but wants "
|
|
|
"to flush %d bytes. (Marked at %s:%d)",
|
|
|
escaped_safe_str_client(conn->address),
|
|
|
- conn->s, conn_type_to_string(conn->type), conn->state,
|
|
|
+ (int)conn->s, conn_type_to_string(conn->type), conn->state,
|
|
|
(int)conn->outbuf_flushlen,
|
|
|
conn->marked_for_close_file, conn->marked_for_close);
|
|
|
if (conn->linked_conn) {
|
|
@@ -797,7 +799,7 @@ conn_close_if_marked(int i)
|
|
|
if (retval > 0) {
|
|
|
LOG_FN_CONN(conn, (LOG_INFO,LD_NET,
|
|
|
"Holding conn (fd %d) open for more flushing.",
|
|
|
- conn->s));
|
|
|
+ (int)conn->s));
|
|
|
conn->timestamp_lastwritten = now; /* reset so we can flush more */
|
|
|
}
|
|
|
return 0;
|
|
@@ -819,7 +821,7 @@ conn_close_if_marked(int i)
|
|
|
"(fd %d, type %s, state %d, marked at %s:%d).",
|
|
|
(int)connection_get_outbuf_len(conn),
|
|
|
escaped_safe_str_client(conn->address),
|
|
|
- conn->s, conn_type_to_string(conn->type), conn->state,
|
|
|
+ (int)conn->s, conn_type_to_string(conn->type), conn->state,
|
|
|
conn->marked_for_close_file,
|
|
|
conn->marked_for_close);
|
|
|
}
|
|
@@ -932,7 +934,7 @@ run_connection_housekeeping(int i, time_t now)
|
|
|
(!DIR_CONN_IS_SERVER(conn) &&
|
|
|
conn->timestamp_lastread + DIR_CONN_MAX_STALL < now))) {
|
|
|
log_info(LD_DIR,"Expiring wedged directory conn (fd %d, purpose %d)",
|
|
|
- conn->s, conn->purpose);
|
|
|
+ (int)conn->s, conn->purpose);
|
|
|
/* This check is temporary; it's to let us know whether we should consider
|
|
|
* parsing partial serverdesc responses. */
|
|
|
if (conn->purpose == DIR_PURPOSE_FETCH_SERVERDESC &&
|
|
@@ -964,7 +966,7 @@ run_connection_housekeeping(int i, time_t now)
|
|
|
* mark it now. */
|
|
|
log_info(LD_OR,
|
|
|
"Expiring non-used OR connection to fd %d (%s:%d) [Too old].",
|
|
|
- conn->s, conn->address, conn->port);
|
|
|
+ (int)conn->s, conn->address, conn->port);
|
|
|
if (conn->state == OR_CONN_STATE_CONNECTING)
|
|
|
connection_or_connect_failed(TO_OR_CONN(conn),
|
|
|
END_OR_CONN_REASON_TIMEOUT,
|
|
@@ -974,7 +976,7 @@ run_connection_housekeeping(int i, time_t now)
|
|
|
if (past_keepalive) {
|
|
|
/* We never managed to actually get this connection open and happy. */
|
|
|
log_info(LD_OR,"Expiring non-open OR connection to fd %d (%s:%d).",
|
|
|
- conn->s,conn->address, conn->port);
|
|
|
+ (int)conn->s,conn->address, conn->port);
|
|
|
connection_mark_for_close(conn);
|
|
|
}
|
|
|
} else if (we_are_hibernating() && !or_conn->n_circuits &&
|
|
@@ -982,13 +984,13 @@ run_connection_housekeeping(int i, time_t now)
|
|
|
/* We're hibernating, there's no circuits, and nothing to flush.*/
|
|
|
log_info(LD_OR,"Expiring non-used OR connection to fd %d (%s:%d) "
|
|
|
"[Hibernating or exiting].",
|
|
|
- conn->s,conn->address, conn->port);
|
|
|
+ (int)conn->s,conn->address, conn->port);
|
|
|
connection_mark_and_flush(conn);
|
|
|
} else if (!or_conn->n_circuits &&
|
|
|
now >= or_conn->timestamp_last_added_nonpadding +
|
|
|
IDLE_OR_CONN_TIMEOUT) {
|
|
|
log_info(LD_OR,"Expiring non-used OR connection to fd %d (%s:%d) "
|
|
|
- "[idle %d].", conn->s,conn->address, conn->port,
|
|
|
+ "[idle %d].", (int)conn->s,conn->address, conn->port,
|
|
|
(int)(now - or_conn->timestamp_last_added_nonpadding));
|
|
|
connection_mark_for_close(conn);
|
|
|
} else if (
|
|
@@ -997,7 +999,7 @@ run_connection_housekeeping(int i, time_t now)
|
|
|
log_fn(LOG_PROTOCOL_WARN,LD_PROTOCOL,
|
|
|
"Expiring stuck OR connection to fd %d (%s:%d). (%d bytes to "
|
|
|
"flush; %d seconds since last write)",
|
|
|
- conn->s, conn->address, conn->port,
|
|
|
+ (int)conn->s, conn->address, conn->port,
|
|
|
(int)connection_get_outbuf_len(conn),
|
|
|
(int)(now-conn->timestamp_lastwritten));
|
|
|
connection_mark_for_close(conn);
|
|
@@ -1939,7 +1941,7 @@ dumpstats(int severity)
|
|
|
int i = conn_sl_idx;
|
|
|
log(severity, LD_GENERAL,
|
|
|
"Conn %d (socket %d) type %d (%s), state %d (%s), created %d secs ago",
|
|
|
- i, conn->s, conn->type, conn_type_to_string(conn->type),
|
|
|
+ i, (int)conn->s, conn->type, conn_type_to_string(conn->type),
|
|
|
conn->state, conn_state_to_string(conn->type, conn->state),
|
|
|
(int)(now - conn->timestamp_created));
|
|
|
if (!connection_is_listener(conn)) {
|