Merge remote-tracking branch 'origin/maint-0.2.2'

Conflicts:
	src/common/compat.c
	src/or/main.c
This commit is contained in:
Nick Mathewson 2011-05-30 14:58:26 -04:00
commit 21de9d46e2
16 changed files with 121 additions and 98 deletions

4
changes/bug3270 Normal file
View File

@ -0,0 +1,4 @@
o Minor bugfixes
- Use a wide type to hold sockets when built for 64-bit Windows builds.
Fixes bug 3270.

View File

@ -870,7 +870,7 @@ socket_accounting_unlock(void)
* Windows, where close()ing a socket doesn't work. Returns 0 on success, -1 * Windows, where close()ing a socket doesn't work. Returns 0 on success, -1
* on failure. */ * on failure. */
int int
tor_close_socket(int s) tor_close_socket(tor_socket_t s)
{ {
int r = 0; int r = 0;
@ -923,8 +923,10 @@ tor_close_socket(int s)
/** Helper: if DEBUG_SOCKET_COUNTING is enabled, remember that <b>s</b> is /** Helper: if DEBUG_SOCKET_COUNTING is enabled, remember that <b>s</b> is
* now an open socket. */ * now an open socket. */
static INLINE void static INLINE void
mark_socket_open(int s) mark_socket_open(tor_socket_t s)
{ {
/* XXXX This bitarray business will NOT work on windows: sockets aren't
small ints there. */
if (s > max_socket) { if (s > max_socket) {
if (max_socket == -1) { if (max_socket == -1) {
open_sockets = bitarray_init_zero(s+128); open_sockets = bitarray_init_zero(s+128);
@ -946,16 +948,16 @@ mark_socket_open(int s)
/** @} */ /** @} */
/** As socket(), but counts the number of open sockets. */ /** As socket(), but counts the number of open sockets. */
int tor_socket_t
tor_open_socket(int domain, int type, int protocol) tor_open_socket(int domain, int type, int protocol)
{ {
int s; tor_socket_t s;
#ifdef SOCK_CLOEXEC #ifdef SOCK_CLOEXEC
#define LINUX_CLOEXEC_OPEN_SOCKET #define LINUX_CLOEXEC_OPEN_SOCKET
type |= SOCK_CLOEXEC; type |= SOCK_CLOEXEC;
#endif #endif
s = socket(domain, type, protocol); s = socket(domain, type, protocol);
if (s >= 0) { if (SOCKET_OK(s)) {
#if !defined(LINUX_CLOEXEC_OPEN_SOCKET) && defined(FD_CLOEXEC) #if !defined(LINUX_CLOEXEC_OPEN_SOCKET) && defined(FD_CLOEXEC)
fcntl(s, F_SETFD, FD_CLOEXEC); fcntl(s, F_SETFD, FD_CLOEXEC);
#endif #endif
@ -968,17 +970,17 @@ tor_open_socket(int domain, int type, int protocol)
} }
/** As socket(), but counts the number of open sockets. */ /** As socket(), but counts the number of open sockets. */
int tor_socket_t
tor_accept_socket(int sockfd, struct sockaddr *addr, socklen_t *len) tor_accept_socket(int sockfd, struct sockaddr *addr, socklen_t *len)
{ {
int s; tor_socket_t s;
#if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
#define LINUX_CLOEXEC_ACCEPT #define LINUX_CLOEXEC_ACCEPT
s = accept4(sockfd, addr, len, SOCK_CLOEXEC); s = accept4(sockfd, addr, len, SOCK_CLOEXEC);
#else #else
s = accept(sockfd, addr, len); s = accept(sockfd, addr, len);
#endif #endif
if (s >= 0) { if (SOCKET_OK(s)) {
#if !defined(LINUX_CLOEXEC_ACCEPT) && defined(FD_CLOEXEC) #if !defined(LINUX_CLOEXEC_ACCEPT) && defined(FD_CLOEXEC)
fcntl(s, F_SETFD, FD_CLOEXEC); fcntl(s, F_SETFD, FD_CLOEXEC);
#endif #endif
@ -1004,7 +1006,7 @@ get_n_open_sockets(void)
/** Turn <b>socket</b> into a nonblocking socket. /** Turn <b>socket</b> into a nonblocking socket.
*/ */
void void
set_socket_nonblocking(int socket) set_socket_nonblocking(tor_socket_t socket)
{ {
#if defined(MS_WINDOWS) #if defined(MS_WINDOWS)
unsigned long nonblocking = 1; unsigned long nonblocking = 1;
@ -1032,7 +1034,7 @@ set_socket_nonblocking(int socket)
**/ **/
/* It would be nicer just to set errno, but that won't work for windows. */ /* It would be nicer just to set errno, but that won't work for windows. */
int int
tor_socketpair(int family, int type, int protocol, int fd[2]) tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2])
{ {
//don't use win32 socketpairs (they are always bad) //don't use win32 socketpairs (they are always bad)
#if defined(HAVE_SOCKETPAIR) && !defined(MS_WINDOWS) #if defined(HAVE_SOCKETPAIR) && !defined(MS_WINDOWS)
@ -1066,9 +1068,9 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
* for now, and really, when localhost is down sometimes, we * for now, and really, when localhost is down sometimes, we
* have other problems too. * have other problems too.
*/ */
int listener = -1; tor_socket_t listener = -1;
int connector = -1; tor_socket_t connector = -1;
int acceptor = -1; tor_socket_t acceptor = -1;
struct sockaddr_in listen_addr; struct sockaddr_in listen_addr;
struct sockaddr_in connect_addr; struct sockaddr_in connect_addr;
int size; int size;
@ -2678,11 +2680,11 @@ in_main_thread(void)
*/ */
#if defined(MS_WINDOWS) #if defined(MS_WINDOWS)
int int
tor_socket_errno(int sock) tor_socket_errno(tor_socket_t sock)
{ {
int optval, optvallen=sizeof(optval); int optval, optvallen=sizeof(optval);
int err = WSAGetLastError(); int err = WSAGetLastError();
if (err == WSAEWOULDBLOCK && sock >= 0) { if (err == WSAEWOULDBLOCK && SOCKET_OK(sock)) {
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void*)&optval, &optvallen)) if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void*)&optval, &optvallen))
return err; return err;
if (optval) if (optval)

View File

@ -395,9 +395,18 @@ int tor_fd_seekend(int fd);
typedef int socklen_t; typedef int socklen_t;
#endif #endif
int tor_close_socket(int s); #ifdef MS_WINDOWS
int tor_open_socket(int domain, int type, int protocol); #define tor_socket_t intptr_t
int tor_accept_socket(int sockfd, struct sockaddr *addr, socklen_t *len); #define SOCKET_OK(s) ((s) != INVALID_SOCKET)
#else
#define tor_socket_t int
#define SOCKET_OK(s) ((s) >= 0)
#endif
int tor_close_socket(tor_socket_t s);
tor_socket_t tor_open_socket(int domain, int type, int protocol);
tor_socket_t tor_accept_socket(int sockfd, struct sockaddr *addr,
socklen_t *len);
int get_n_open_sockets(void); int get_n_open_sockets(void);
#define tor_socket_send(s, buf, len, flags) send(s, buf, len, flags) #define tor_socket_send(s, buf, len, flags) send(s, buf, len, flags)
@ -469,8 +478,8 @@ int tor_inet_aton(const char *cp, struct in_addr *addr) ATTR_NONNULL((1,2));
const char *tor_inet_ntop(int af, const void *src, char *dst, size_t len); const char *tor_inet_ntop(int af, const void *src, char *dst, size_t len);
int tor_inet_pton(int af, const char *src, void *dst); int tor_inet_pton(int af, const char *src, void *dst);
int tor_lookup_hostname(const char *name, uint32_t *addr) ATTR_NONNULL((1,2)); int tor_lookup_hostname(const char *name, uint32_t *addr) ATTR_NONNULL((1,2));
void set_socket_nonblocking(int socket); void set_socket_nonblocking(tor_socket_t socket);
int tor_socketpair(int family, int type, int protocol, int fd[2]); int tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2]);
int network_init(void); int network_init(void);
/* For stupid historical reasons, windows sockets have an independent /* For stupid historical reasons, windows sockets have an independent
@ -497,7 +506,7 @@ int network_init(void);
((e) == WSAEMFILE || (e) == WSAENOBUFS) ((e) == WSAEMFILE || (e) == WSAENOBUFS)
/** Return true if e is EADDRINUSE or the local equivalent. */ /** Return true if e is EADDRINUSE or the local equivalent. */
#define ERRNO_IS_EADDRINUSE(e) ((e) == WSAEADDRINUSE) #define ERRNO_IS_EADDRINUSE(e) ((e) == WSAEADDRINUSE)
int tor_socket_errno(int sock); int tor_socket_errno(tor_socket_t sock);
const char *tor_socket_strerror(int e); const char *tor_socket_strerror(int e);
#else #else
#define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN) #define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN)

View File

@ -12,11 +12,15 @@ struct event_base;
struct bufferevent; struct bufferevent;
#endif #endif
#ifdef HAVE_EVENT2_EVENT_H #ifdef HAVE_EVENT2_EVENT_H
#include <event2/util.h> #include <event2/util.h>
#else #else
#ifndef EVUTIL_SOCKET_DEFINED
#define EVUTIL_SOCKET_DEFINED
#define evutil_socket_t int #define evutil_socket_t int
#endif #endif
#endif
void configure_libevent_logging(void); void configure_libevent_logging(void);
void suppress_libevent_log_msg(const char *msg); void suppress_libevent_log_msg(const char *msg);

View File

@ -1573,7 +1573,7 @@ rate_limit_log(ratelim_t *lim, time_t now)
* was returned by open(). Return the number of bytes written, or -1 * was returned by open(). Return the number of bytes written, or -1
* on error. Only use if fd is a blocking fd. */ * on error. Only use if fd is a blocking fd. */
ssize_t ssize_t
write_all(int fd, const char *buf, size_t count, int isSocket) write_all(tor_socket_t fd, const char *buf, size_t count, int isSocket)
{ {
size_t written = 0; size_t written = 0;
ssize_t result; ssize_t result;
@ -1583,7 +1583,7 @@ write_all(int fd, const char *buf, size_t count, int isSocket)
if (isSocket) if (isSocket)
result = tor_socket_send(fd, buf+written, count-written, 0); result = tor_socket_send(fd, buf+written, count-written, 0);
else else
result = write(fd, buf+written, count-written); result = write((int)fd, buf+written, count-written);
if (result<0) if (result<0)
return -1; return -1;
written += result; written += result;
@ -1597,7 +1597,7 @@ write_all(int fd, const char *buf, size_t count, int isSocket)
* open(). Return the number of bytes read, or -1 on error. Only use * open(). Return the number of bytes read, or -1 on error. Only use
* if fd is a blocking fd. */ * if fd is a blocking fd. */
ssize_t ssize_t
read_all(int fd, char *buf, size_t count, int isSocket) read_all(tor_socket_t fd, char *buf, size_t count, int isSocket)
{ {
size_t numread = 0; size_t numread = 0;
ssize_t result; ssize_t result;
@ -1609,7 +1609,7 @@ read_all(int fd, char *buf, size_t count, int isSocket)
if (isSocket) if (isSocket)
result = tor_socket_recv(fd, buf+numread, count-numread, 0); result = tor_socket_recv(fd, buf+numread, count-numread, 0);
else else
result = read(fd, buf+numread, count-numread); result = read((int)fd, buf+numread, count-numread);
if (result<0) if (result<0)
return -1; return -1;
else if (result == 0) else if (result == 0)

View File

@ -276,8 +276,8 @@ typedef struct ratelim_t {
char *rate_limit_log(ratelim_t *lim, time_t now); char *rate_limit_log(ratelim_t *lim, time_t now);
/* File helpers */ /* File helpers */
ssize_t write_all(int fd, const char *buf, size_t count, int isSocket); ssize_t write_all(tor_socket_t fd, const char *buf, size_t count, int isSocket);
ssize_t read_all(int fd, char *buf, size_t count, int isSocket); ssize_t read_all(tor_socket_t fd, char *buf, size_t count, int isSocket);
/** Return values from file_status(); see that function's documentation /** Return values from file_status(); see that function's documentation
* for details. */ * for details. */

View File

@ -588,7 +588,7 @@ buf_add_chunk_with_capacity(buf_t *buf, size_t capacity, int capped)
* *<b>reached_eof</b> to 1. Return -1 on error, 0 on eof or blocking, * *<b>reached_eof</b> to 1. Return -1 on error, 0 on eof or blocking,
* and the number of bytes read otherwise. */ * and the number of bytes read otherwise. */
static INLINE int static INLINE int
read_to_chunk(buf_t *buf, chunk_t *chunk, int fd, size_t at_most, read_to_chunk(buf_t *buf, chunk_t *chunk, tor_socket_t fd, size_t at_most,
int *reached_eof, int *socket_error) int *reached_eof, int *socket_error)
{ {
ssize_t read_result; ssize_t read_result;
@ -645,7 +645,7 @@ read_to_chunk_tls(buf_t *buf, chunk_t *chunk, tor_tls_t *tls,
*/ */
/* XXXX023 indicate "read blocked" somehow? */ /* XXXX023 indicate "read blocked" somehow? */
int int
read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof, read_to_buf(tor_socket_t s, size_t at_most, buf_t *buf, int *reached_eof,
int *socket_error) int *socket_error)
{ {
/* XXXX023 It's stupid to overload the return values for these functions: /* XXXX023 It's stupid to overload the return values for these functions:
@ -744,7 +744,7 @@ read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf)
* written on success, 0 on blocking, -1 on failure. * written on success, 0 on blocking, -1 on failure.
*/ */
static INLINE int static INLINE int
flush_chunk(int s, buf_t *buf, chunk_t *chunk, size_t sz, flush_chunk(tor_socket_t s, buf_t *buf, chunk_t *chunk, size_t sz,
size_t *buf_flushlen) size_t *buf_flushlen)
{ {
ssize_t write_result; ssize_t write_result;
@ -816,7 +816,7 @@ flush_chunk_tls(tor_tls_t *tls, buf_t *buf, chunk_t *chunk,
* -1 on failure. Return 0 if write() would block. * -1 on failure. Return 0 if write() would block.
*/ */
int int
flush_buf(int s, buf_t *buf, size_t sz, size_t *buf_flushlen) flush_buf(tor_socket_t s, buf_t *buf, size_t sz, size_t *buf_flushlen)
{ {
/* XXXX023 It's stupid to overload the return values for these functions: /* XXXX023 It's stupid to overload the return values for these functions:
* "error status" and "number of bytes flushed" are not mutually exclusive. * "error status" and "number of bytes flushed" are not mutually exclusive.

View File

@ -24,11 +24,11 @@ size_t buf_datalen(const buf_t *buf);
size_t buf_allocation(const buf_t *buf); size_t buf_allocation(const buf_t *buf);
size_t buf_slack(const buf_t *buf); size_t buf_slack(const buf_t *buf);
int read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof, int read_to_buf(tor_socket_t s, size_t at_most, buf_t *buf, int *reached_eof,
int *socket_error); int *socket_error);
int read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf); int read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf);
int flush_buf(int s, buf_t *buf, size_t sz, size_t *buf_flushlen); int flush_buf(tor_socket_t s, buf_t *buf, size_t sz, size_t *buf_flushlen);
int flush_buf_tls(tor_tls_t *tls, buf_t *buf, size_t sz, size_t *buf_flushlen); int flush_buf_tls(tor_tls_t *tls, buf_t *buf, size_t sz, size_t *buf_flushlen);
int write_to_buf(const char *string, size_t string_len, buf_t *buf); int write_to_buf(const char *string, size_t string_len, buf_t *buf);

View File

@ -60,8 +60,8 @@ static int connection_reached_eof(connection_t *conn);
static int connection_read_to_buf(connection_t *conn, ssize_t *max_to_read, static int connection_read_to_buf(connection_t *conn, ssize_t *max_to_read,
int *socket_error); int *socket_error);
static int connection_process_inbuf(connection_t *conn, int package_partial); static int connection_process_inbuf(connection_t *conn, int package_partial);
static void client_check_address_changed(int sock); static void client_check_address_changed(tor_socket_t sock);
static void set_constrained_socket_buffers(int sock, int size); static void set_constrained_socket_buffers(tor_socket_t sock, int size);
static const char *connection_proxy_state_to_string(int state); static const char *connection_proxy_state_to_string(int state);
static int connection_read_https_proxy_response(connection_t *conn); static int connection_read_https_proxy_response(connection_t *conn);
@ -478,8 +478,8 @@ _connection_free(connection_t *conn)
rend_data_free(dir_conn->rend_data); rend_data_free(dir_conn->rend_data);
} }
if (conn->s >= 0) { if (SOCKET_OK(conn->s)) {
log_debug(LD_NET,"closing fd %d.",conn->s); log_debug(LD_NET,"closing fd %d.",(int)conn->s);
tor_close_socket(conn->s); tor_close_socket(conn->s);
conn->s = -1; conn->s = -1;
} }
@ -706,14 +706,14 @@ connection_close_immediate(connection_t *conn)
} }
if (conn->outbuf_flushlen) { if (conn->outbuf_flushlen) {
log_info(LD_NET,"fd %d, type %s, state %s, %d bytes on outbuf.", log_info(LD_NET,"fd %d, type %s, state %s, %d bytes on outbuf.",
conn->s, conn_type_to_string(conn->type), (int)conn->s, conn_type_to_string(conn->type),
conn_state_to_string(conn->type, conn->state), conn_state_to_string(conn->type, conn->state),
(int)conn->outbuf_flushlen); (int)conn->outbuf_flushlen);
} }
connection_unregister_events(conn); connection_unregister_events(conn);
if (conn->s >= 0) if (SOCKET_OK(conn->s))
tor_close_socket(conn->s); tor_close_socket(conn->s);
conn->s = -1; conn->s = -1;
if (conn->linked) if (conn->linked)
@ -782,7 +782,7 @@ connection_expire_held_open(void)
log_fn(severity, LD_NET, log_fn(severity, LD_NET,
"Giving up on marked_for_close conn that's been flushing " "Giving up on marked_for_close conn that's been flushing "
"for 15s (fd %d, type %s, state %s).", "for 15s (fd %d, type %s, state %s).",
conn->s, conn_type_to_string(conn->type), (int)conn->s, conn_type_to_string(conn->type),
conn_state_to_string(conn->type, conn->state)); conn_state_to_string(conn->type, conn->state));
conn->hold_open_until_flushed = 0; conn->hold_open_until_flushed = 0;
} }
@ -935,7 +935,7 @@ check_location_for_unix_socket(or_options_t *options, const char *path)
/** Tell the TCP stack that it shouldn't wait for a long time after /** Tell the TCP stack that it shouldn't wait for a long time after
* <b>sock</b> has closed before reusing its port. */ * <b>sock</b> has closed before reusing its port. */
static void static void
make_socket_reuseable(int sock) make_socket_reuseable(tor_socket_t sock)
{ {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
(void) sock; (void) sock;
@ -963,7 +963,7 @@ connection_create_listener(const struct sockaddr *listensockaddr,
int type, char* address) int type, char* address)
{ {
connection_t *conn; connection_t *conn;
int s; /* the socket we're going to make */ tor_socket_t s; /* the socket we're going to make */
uint16_t usePort = 0, gotPort = 0; uint16_t usePort = 0, gotPort = 0;
int start_reading = 0; int start_reading = 0;
@ -986,7 +986,7 @@ connection_create_listener(const struct sockaddr *listensockaddr,
s = tor_open_socket(PF_INET, s = tor_open_socket(PF_INET,
is_tcp ? SOCK_STREAM : SOCK_DGRAM, is_tcp ? SOCK_STREAM : SOCK_DGRAM,
is_tcp ? IPPROTO_TCP: IPPROTO_UDP); is_tcp ? IPPROTO_TCP: IPPROTO_UDP);
if (s < 0) { if (!SOCKET_OK(s)) {
log_warn(LD_NET,"Socket creation failed."); log_warn(LD_NET,"Socket creation failed.");
goto err; goto err;
} }
@ -1179,7 +1179,7 @@ check_sockaddr_family_match(sa_family_t got, connection_t *listener)
static int static int
connection_handle_listener_read(connection_t *conn, int new_type) connection_handle_listener_read(connection_t *conn, int new_type)
{ {
int news; /* the new socket */ tor_socket_t news; /* the new socket */
connection_t *newconn; connection_t *newconn;
/* information about the remote peer when connecting to other routers */ /* information about the remote peer when connecting to other routers */
char addrbuf[256]; char addrbuf[256];
@ -1192,7 +1192,7 @@ connection_handle_listener_read(connection_t *conn, int new_type)
memset(addrbuf, 0, sizeof(addrbuf)); memset(addrbuf, 0, sizeof(addrbuf));
news = tor_accept_socket(conn->s,remote,&remotelen); news = tor_accept_socket(conn->s,remote,&remotelen);
if (news < 0) { /* accept() error */ if (!SOCKET_OK(news)) { /* accept() error */
int e = tor_socket_errno(conn->s); int e = tor_socket_errno(conn->s);
if (ERRNO_IS_ACCEPT_EAGAIN(e)) { if (ERRNO_IS_ACCEPT_EAGAIN(e)) {
return 0; /* he hung up before we could accept(). that's fine. */ return 0; /* he hung up before we could accept(). that's fine. */
@ -1208,7 +1208,7 @@ connection_handle_listener_read(connection_t *conn, int new_type)
} }
log_debug(LD_NET, log_debug(LD_NET,
"Connection accepted on socket %d (child of fd %d).", "Connection accepted on socket %d (child of fd %d).",
news,conn->s); (int)news,(int)conn->s);
make_socket_reuseable(news); make_socket_reuseable(news);
set_socket_nonblocking(news); set_socket_nonblocking(news);
@ -1361,7 +1361,8 @@ int
connection_connect(connection_t *conn, const char *address, connection_connect(connection_t *conn, const char *address,
const tor_addr_t *addr, uint16_t port, int *socket_error) const tor_addr_t *addr, uint16_t port, int *socket_error)
{ {
int s, inprogress = 0; tor_socket_t s;
int inprogress = 0;
char addrbuf[256]; char addrbuf[256];
struct sockaddr *dest_addr; struct sockaddr *dest_addr;
int dest_addr_len; int dest_addr_len;
@ -2482,7 +2483,7 @@ connection_bucket_refill(int seconds_elapsed, time_t now)
TO_OR_CONN(conn)->read_bucket > 0)) { TO_OR_CONN(conn)->read_bucket > 0)) {
/* and either a non-cell conn or a cell conn with non-empty bucket */ /* and either a non-cell conn or a cell conn with non-empty bucket */
LOG_FN_CONN(conn, (LOG_DEBUG,LD_NET, LOG_FN_CONN(conn, (LOG_DEBUG,LD_NET,
"waking up conn (fd %d) for read", conn->s)); "waking up conn (fd %d) for read", (int)conn->s));
conn->read_blocked_on_bw = 0; conn->read_blocked_on_bw = 0;
connection_start_reading(conn); connection_start_reading(conn);
} }
@ -2495,7 +2496,7 @@ connection_bucket_refill(int seconds_elapsed, time_t now)
conn->state != OR_CONN_STATE_OPEN || conn->state != OR_CONN_STATE_OPEN ||
TO_OR_CONN(conn)->write_bucket > 0)) { TO_OR_CONN(conn)->write_bucket > 0)) {
LOG_FN_CONN(conn, (LOG_DEBUG,LD_NET, LOG_FN_CONN(conn, (LOG_DEBUG,LD_NET,
"waking up conn (fd %d) for write", conn->s)); "waking up conn (fd %d) for write", (int)conn->s));
conn->write_blocked_on_bw = 0; conn->write_blocked_on_bw = 0;
connection_start_writing(conn); connection_start_writing(conn);
} }
@ -2769,7 +2770,7 @@ connection_read_to_buf(connection_t *conn, ssize_t *max_to_read,
log_debug(LD_NET, log_debug(LD_NET,
"%d: starting, inbuf_datalen %ld (%d pending in tls object)." "%d: starting, inbuf_datalen %ld (%d pending in tls object)."
" at_most %ld.", " at_most %ld.",
conn->s,(long)buf_datalen(conn->inbuf), (int)conn->s,(long)buf_datalen(conn->inbuf),
tor_tls_get_pending_bytes(or_conn->tls), (long)at_most); tor_tls_get_pending_bytes(or_conn->tls), (long)at_most);
initial_size = buf_datalen(conn->inbuf); initial_size = buf_datalen(conn->inbuf);
@ -3131,7 +3132,7 @@ connection_handle_write_impl(connection_t *conn, int force)
tor_assert(!connection_is_listener(conn)); tor_assert(!connection_is_listener(conn));
if (conn->marked_for_close || conn->s < 0) if (conn->marked_for_close || !SOCKET_OK(conn->s))
return 0; /* do nothing */ return 0; /* do nothing */
if (conn->in_flushed_some) { if (conn->in_flushed_some) {
@ -3365,12 +3366,13 @@ _connection_write_to_buf_impl(const char *string, size_t len,
/* if it failed, it means we have our package/delivery windows set /* if it failed, it means we have our package/delivery windows set
wrong compared to our max outbuf size. close the whole circuit. */ wrong compared to our max outbuf size. close the whole circuit. */
log_warn(LD_NET, log_warn(LD_NET,
"write_to_buf failed. Closing circuit (fd %d).", conn->s); "write_to_buf failed. Closing circuit (fd %d).", (int)conn->s);
circuit_mark_for_close(circuit_get_by_edge_conn(TO_EDGE_CONN(conn)), circuit_mark_for_close(circuit_get_by_edge_conn(TO_EDGE_CONN(conn)),
END_CIRC_REASON_INTERNAL); END_CIRC_REASON_INTERNAL);
} else { } else {
log_warn(LD_NET, log_warn(LD_NET,
"write_to_buf failed. Closing connection (fd %d).", conn->s); "write_to_buf failed. Closing connection (fd %d).",
(int)conn->s);
connection_mark_for_close(conn); connection_mark_for_close(conn);
} }
return; return;
@ -3416,7 +3418,7 @@ _connection_write_to_buf_impl(const char *string, size_t len,
/* this connection is broken. remove it. */ /* this connection is broken. remove it. */
log_warn(LD_BUG, "unhandled error on write for " log_warn(LD_BUG, "unhandled error on write for "
"conn (type %d, fd %d); removing", "conn (type %d, fd %d); removing",
conn->type, conn->s); conn->type, (int)conn->s);
tor_fragile_assert(); tor_fragile_assert();
/* do a close-immediate here, so we don't try to flush */ /* do a close-immediate here, so we don't try to flush */
connection_close_immediate(conn); connection_close_immediate(conn);
@ -3665,7 +3667,7 @@ alloc_http_authenticator(const char *authenticator)
* call init_keys(). * call init_keys().
*/ */
static void static void
client_check_address_changed(int sock) client_check_address_changed(tor_socket_t sock)
{ {
uint32_t iface_ip, ip_out; /* host order */ uint32_t iface_ip, ip_out; /* host order */
struct sockaddr_in out_addr; struct sockaddr_in out_addr;
@ -3721,7 +3723,7 @@ client_check_address_changed(int sock)
* to the desired size to stay below system TCP buffer limits. * to the desired size to stay below system TCP buffer limits.
*/ */
static void static void
set_constrained_socket_buffers(int sock, int size) set_constrained_socket_buffers(tor_socket_t sock, int size)
{ {
void *sz = (void*)&size; void *sz = (void*)&size;
socklen_t sz_sz = (socklen_t) sizeof(size); socklen_t sz_sz = (socklen_t) sizeof(size);
@ -3966,7 +3968,7 @@ assert_connection_ok(connection_t *conn, time_t now)
tor_assert(conn->linked); tor_assert(conn->linked);
} }
if (conn->linked) if (conn->linked)
tor_assert(conn->s < 0); tor_assert(!SOCKET_OK(conn->s));
if (conn->outbuf_flushlen > 0) { if (conn->outbuf_flushlen > 0) {
/* With optimistic data, we may have queued data in /* With optimistic data, we may have queued data in

View File

@ -1577,7 +1577,7 @@ getinfo_helper_listeners(control_connection_t *control_conn,
struct sockaddr_storage ss; struct sockaddr_storage ss;
socklen_t ss_len = sizeof(ss); socklen_t ss_len = sizeof(ss);
if (conn->type != type || conn->marked_for_close || conn->s < 0) if (conn->type != type || conn->marked_for_close || !SOCKET_OK(conn->s))
continue; continue;
if (getsockname(conn->s, (struct sockaddr *)&ss, &ss_len) < 0) { if (getsockname(conn->s, (struct sockaddr *)&ss, &ss_len) < 0) {

View File

@ -225,8 +225,8 @@ cpuworker_main(void *data)
{ {
char question[ONIONSKIN_CHALLENGE_LEN]; char question[ONIONSKIN_CHALLENGE_LEN];
uint8_t question_type; uint8_t question_type;
int *fdarray = data; tor_socket_t *fdarray = data;
int fd; tor_socket_t fd;
/* variables for onion processing */ /* variables for onion processing */
char keys[CPATH_KEY_MATERIAL_LEN]; char keys[CPATH_KEY_MATERIAL_LEN];
@ -316,12 +316,12 @@ cpuworker_main(void *data)
static int static int
spawn_cpuworker(void) spawn_cpuworker(void)
{ {
int *fdarray; tor_socket_t *fdarray;
int fd; tor_socket_t fd;
connection_t *conn; connection_t *conn;
int err; int err;
fdarray = tor_malloc(sizeof(int)*2); fdarray = tor_malloc(sizeof(tor_socket_t)*2);
if ((err = tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fdarray)) < 0) { if ((err = tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fdarray)) < 0) {
log_warn(LD_NET, "Couldn't construct socketpair for cpuworker: %s", log_warn(LD_NET, "Couldn't construct socketpair for cpuworker: %s",
tor_socket_strerror(-err)); tor_socket_strerror(-err));

View File

@ -306,7 +306,7 @@ void
dnsserv_configure_listener(connection_t *conn) dnsserv_configure_listener(connection_t *conn)
{ {
tor_assert(conn); tor_assert(conn);
tor_assert(conn->s >= 0); tor_assert(SOCKET_OK(conn->s));
tor_assert(conn->type == CONN_TYPE_AP_DNS_LISTENER); tor_assert(conn->type == CONN_TYPE_AP_DNS_LISTENER);
conn->dns_server_port = conn->dns_server_port =

View File

@ -1563,7 +1563,7 @@ evdns_request_data_build(const char *const name, const size_t name_len,
/* exported function */ /* exported function */
struct evdns_server_port * struct evdns_server_port *
evdns_add_server_port(int socket, int is_tcp, evdns_request_callback_fn_type cb, void *user_data) evdns_add_server_port(tor_socket_t socket, int is_tcp, evdns_request_callback_fn_type cb, void *user_data)
{ {
struct evdns_server_port *port; struct evdns_server_port *port;
if (!(port = mm_malloc(sizeof(struct evdns_server_port)))) if (!(port = mm_malloc(sizeof(struct evdns_server_port))))

View File

@ -319,7 +319,7 @@ typedef void (*evdns_request_callback_fn_type)(struct evdns_server_request *, vo
#define EVDNS_CLASS_INET 1 #define EVDNS_CLASS_INET 1
struct evdns_server_port *evdns_add_server_port(int socket, int is_tcp, evdns_request_callback_fn_type callback, void *user_data); struct evdns_server_port *evdns_add_server_port(tor_socket_t socket, int is_tcp, evdns_request_callback_fn_type callback, void *user_data);
void evdns_close_server_port(struct evdns_server_port *port); void evdns_close_server_port(struct evdns_server_port *port);
int evdns_server_request_add_reply(struct evdns_server_request *req, int section, const char *name, int type, int class, int ttl, int datalen, int is_name, const char *data); int evdns_server_request_add_reply(struct evdns_server_request *req, int section, const char *name, int type, int class, int ttl, int datalen, int is_name, const char *data);

View File

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

View File

@ -982,7 +982,7 @@ typedef struct connection_t {
unsigned int proxy_state:4; unsigned int proxy_state:4;
/** Our socket; -1 if this connection is closed, or has no socket. */ /** Our socket; -1 if this connection is closed, or has no socket. */
evutil_socket_t s; tor_socket_t s;
int conn_array_index; /**< Index into the global connection array. */ int conn_array_index; /**< Index into the global connection array. */
struct event *read_event; /**< Libevent event structure. */ struct event *read_event; /**< Libevent event structure. */