diff options
author | Nick Mathewson <nickm@torproject.org> | 2003-08-12 03:08:41 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2003-08-12 03:08:41 +0000 |
commit | c336c99e609b2918ca664bc1fdbfb916a6811508 (patch) | |
tree | ff04c4774b60cef2dce98d88497ac5ac4a3cb8e7 /src/or | |
parent | 5126f203f23773f64b51e5c0c7b7e1d702f26ca9 (diff) | |
download | tor-c336c99e609b2918ca664bc1fdbfb916a6811508.tar tor-c336c99e609b2918ca664bc1fdbfb916a6811508.tar.gz |
Start of port to win32. Missing are:
- signal support
- forking for DNS farm
- changes for async IO
- daemonizing
In other words, some files still don't build, and the ones that do build,
do nonblocking IO incorrectly.
I'm also not checking in the project files till I have a good place
for them.
svn:r380
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/config.c | 2 | ||||
-rw-r--r-- | src/or/connection.c | 8 | ||||
-rw-r--r-- | src/or/connection_edge.c | 2 | ||||
-rw-r--r-- | src/or/connection_exit.c | 2 | ||||
-rw-r--r-- | src/or/connection_or.c | 4 | ||||
-rw-r--r-- | src/or/directory.c | 4 | ||||
-rw-r--r-- | src/or/dns.c | 2 | ||||
-rw-r--r-- | src/or/or.h | 52 | ||||
-rw-r--r-- | src/or/test.c | 15 |
9 files changed, 78 insertions, 13 deletions
diff --git a/src/or/config.c b/src/or/config.c index 9a5c645d7..6d7a31190 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -83,7 +83,7 @@ struct config_line *config_get_lines(FILE *f) { } /* walk to the end, remove end whitespace */ - s = index(line, 0); /* now we're at the null */ + s = strchr(line, 0); /* now we're at the null */ do { *s = 0; s--; diff --git a/src/or/connection.c b/src/or/connection.c index 0b88b4cd4..c75b4b379 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -25,7 +25,7 @@ char *conn_type_to_string[] = { }; char *conn_state_to_string[][15] = { - { }, /* no type associated with 0 */ + { NULL }, /* no type associated with 0 */ { "ready" }, /* op listener, 0 */ { "awaiting keys", /* op, 0 */ "open", /* 1 */ @@ -146,7 +146,7 @@ int connection_create_listener(struct sockaddr_in *bindaddr, int type) { return -1; } - setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); + setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&one, sizeof(one)); if(bind(s,(struct sockaddr *)bindaddr,sizeof(*bindaddr)) < 0) { perror("bind "); @@ -159,7 +159,7 @@ int connection_create_listener(struct sockaddr_in *bindaddr, int type) { return -1; } - fcntl(s, F_SETFL, O_NONBLOCK); /* set s to non-blocking */ + set_socket_nonblocking(s); conn = connection_new(type); if(!conn) { @@ -199,7 +199,7 @@ int connection_handle_listener_read(connection_t *conn, int new_type, int new_st } log(LOG_INFO,"Connection accepted on socket %d (child of fd %d).",news, conn->s); - fcntl(news, F_SETFL, O_NONBLOCK); /* set news to non-blocking */ + set_socket_nonblocking(news); newconn = connection_new(new_type); newconn->s = news; diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 165db46e6..9ce0ab56b 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -264,7 +264,7 @@ int connection_edge_finished_flushing(connection_t *conn) { switch(conn->state) { case EXIT_CONN_STATE_CONNECTING: - if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, &e, &len) < 0) { /* not yet */ + if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0) { /* not yet */ if(errno != EINPROGRESS){ /* yuck. kill it. */ log_fn(LOG_DEBUG,"in-progress exit connect failed. Removing."); diff --git a/src/or/connection_exit.c b/src/or/connection_exit.c index 88f27d2cb..f67440402 100644 --- a/src/or/connection_exit.c +++ b/src/or/connection_exit.c @@ -76,7 +76,7 @@ int connection_exit_connect(connection_t *conn) { log_fn(LOG_ERR,"Error creating network socket."); return -1; } - fcntl(s, F_SETFL, O_NONBLOCK); /* set s to non-blocking */ + set_socket_nonblocking(s); memset((void *)&dest_addr,0,sizeof(dest_addr)); dest_addr.sin_family = AF_INET; diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 2408ebac4..ccf3be06a 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -61,7 +61,7 @@ int connection_or_finished_flushing(connection_t *conn) { case OR_CONN_STATE_OP_SENDING_KEYS: return or_handshake_op_finished_sending_keys(conn); case OR_CONN_STATE_CLIENT_CONNECTING: - if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, &e, &len) < 0) { /* not yet */ + if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0) { /* not yet */ if(errno != EINPROGRESS){ /* yuck. kill it. */ log_fn(LOG_DEBUG,"in-progress connect failed. Removing."); @@ -147,7 +147,7 @@ connection_t *connection_or_connect(routerinfo_t *router) { connection_free(conn); return NULL; } - fcntl(s, F_SETFL, O_NONBLOCK); /* set s to non-blocking */ + set_socket_nonblocking(s); memset((void *)&router_addr,0,sizeof(router_addr)); router_addr.sin_family = AF_INET; diff --git a/src/or/directory.c b/src/or/directory.c index 4ede81fd8..98d207b26 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -56,7 +56,7 @@ void directory_initiate_fetch(routerinfo_t *router) { connection_free(conn); return; } - fcntl(s, F_SETFL, O_NONBLOCK); /* set s to non-blocking */ + set_socket_nonblocking(s); memset((void *)&router_addr,0,sizeof(router_addr)); router_addr.sin_family = AF_INET; @@ -254,7 +254,7 @@ int connection_dir_finished_flushing(connection_t *conn) { switch(conn->state) { case DIR_CONN_STATE_CONNECTING: - if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, &e, &len) < 0) { /* not yet */ + if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0) { /* not yet */ if(errno != EINPROGRESS){ /* yuck. kill it. */ log_fn(LOG_DEBUG,"in-progress connect failed. Removing."); diff --git a/src/or/dns.c b/src/or/dns.c index 080f041ec..64a6bfb8a 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -382,7 +382,7 @@ static int dns_spawn_worker(void) { return -1; } - fcntl(fd[0], F_SETFL, O_NONBLOCK); /* set it to non-blocking */ + set_socket_nonblocking(fd[0]); /* set up conn so it's got all the data we need to remember */ conn->receiver_bucket = -1; /* non-cell connections don't do receiver buckets */ diff --git a/src/or/or.h b/src/or/or.h index dba32795e..821988b32 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -10,11 +10,21 @@ #include <stdio.h> #include <stdlib.h> #include <limits.h> +#ifdef HAVE_UNISTD_H #include <unistd.h> +#endif +#ifdef HAVE_STRING_H #include <string.h> +#endif +#ifdef HAVE_SIGNAL_H #include <signal.h> +#endif +#ifdef HAVE_NETDB_H #include <netdb.h> +#endif +#ifdef HAVE_CTYPE_H #include <ctype.h> +#endif #include "../common/torint.h" #ifdef HAVE_SYS_POLL_H #include <sys/poll.h> @@ -23,17 +33,59 @@ #else #include "../common/fakepoll.h" #endif +#ifdef HAVE_SYS_TYPES_H #include <sys/types.h> +#endif +#ifdef HAVE_SYS_FCNTL_H #include <sys/fcntl.h> +#endif +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif +#ifdef HAVE_SYS_IOCTL_H #include <sys/ioctl.h> +#endif +#ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> +#endif +#ifdef HAVE_SYS_TIME_H #include <sys/time.h> +#endif +#ifdef HAVE_SYS_STAT_H #include <sys/stat.h> +#endif +#ifdef HAVE_NETINET_IN_H #include <netinet/in.h> +#endif +#ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> +#endif +#ifdef HAVE_ERRNO_H #include <errno.h> +#endif +#ifdef HAVE_ASSERT_H #include <assert.h> +#endif +#ifdef HAVE_TIME_H #include <time.h> +#endif +#ifdef HAVE_WINSOCK_H +#include <winsock.h> +#endif +#if _MSC_VER > 1300 +#include <winsock2.h> +#include <ws2tcpip.h> +#elif defined(_MSC_VER) +#include <winsock.h> +#endif + +#ifdef _MSC_VER +#include <io.h> +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#define snprintf +#endif + #include "../common/crypto.h" #include "../common/log.h" diff --git a/src/or/test.c b/src/or/test.c index 881396c55..acc3896af 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -3,7 +3,14 @@ /* $Id$ */ #include <stdio.h> +#ifdef HAVE_FCNTL_H #include <fcntl.h> +#endif + +#ifdef _MSC_VER +/* For mkdir() */ +#include <direct.h> +#endif #include "or.h" #include "../common/test.h" @@ -26,8 +33,14 @@ dump_hex(char *s, int len) void setup_directory() { char buf[256]; + int r; sprintf(buf, "/tmp/tor_test"); - if (mkdir(buf, 0700) && errno != EEXIST) +#ifdef _MSC_VER + r = mkdir(buf); +#else + r = mkdir(buf, 0700); +#endif + if (r && errno != EEXIST) fprintf(stderr, "Can't create directory %s", buf); } |