[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Start of port to win32. Missing are:



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv27211/src/or

Modified Files:
	config.c connection.c connection_edge.c connection_exit.c 
	connection_or.c directory.c dns.c or.h test.c 
Log Message:
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. 



Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- config.c	5 Jul 2003 07:10:34 -0000	1.36
+++ config.c	12 Aug 2003 03:08:40 -0000	1.37
@@ -83,7 +83,7 @@
     }
 
     /* 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--;

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- connection.c	30 Jul 2003 19:12:02 -0000	1.72
+++ connection.c	12 Aug 2003 03:08:40 -0000	1.73
@@ -25,7 +25,7 @@
 };
 
 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 @@
     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 @@
     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 @@
   }
   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;

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- connection_edge.c	3 Jul 2003 03:40:47 -0000	1.15
+++ connection_edge.c	12 Aug 2003 03:08:41 -0000	1.16
@@ -264,7 +264,7 @@
 
   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.");

Index: connection_exit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_exit.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- connection_exit.c	17 Jun 2003 22:18:26 -0000	1.36
+++ connection_exit.c	12 Aug 2003 03:08:41 -0000	1.37
@@ -76,7 +76,7 @@
     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;

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- connection_or.c	30 Jul 2003 19:12:02 -0000	1.36
+++ connection_or.c	12 Aug 2003 03:08:41 -0000	1.37
@@ -61,7 +61,7 @@
     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_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;

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- directory.c	25 Jun 2003 00:31:41 -0000	1.18
+++ directory.c	12 Aug 2003 03:08:41 -0000	1.19
@@ -56,7 +56,7 @@
     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 @@
 
   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.");

Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dns.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- dns.c	27 Jun 2003 00:57:04 -0000	1.16
+++ dns.c	12 Aug 2003 03:08:41 -0000	1.17
@@ -382,7 +382,7 @@
     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 */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- or.h	11 Aug 2003 20:40:21 -0000	1.101
+++ or.h	12 Aug 2003 03:08:41 -0000	1.102
@@ -9,12 +9,22 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <limits.h>
-#include <unistd.h>
-#include <string.h>
-#include <signal.h>
-#include <netdb.h>
-#include <ctype.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>
@@ -22,18 +32,60 @@
 #include <poll.h>
 #else
 #include "../common/fakepoll.h"
-#endif
-#include <sys/types.h>
-#include <sys/fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <errno.h>
-#include <assert.h>
-#include <time.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"

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- test.c	30 Jul 2003 19:10:20 -0000	1.30
+++ test.c	12 Aug 2003 03:08:41 -0000	1.31
@@ -2,8 +2,15 @@
 /* See LICENSE for licensing information */
 /* $Id$ */
 
-#include <stdio.h>
-#include <fcntl.h>
+#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"
@@ -25,9 +32,15 @@
 
 void
 setup_directory() {
-  char buf[256];
-  sprintf(buf, "/tmp/tor_test");
-  if (mkdir(buf, 0700) && errno != EEXIST)
+  char buf[256];
+  int r;
+  sprintf(buf, "/tmp/tor_test");
+#ifdef _MSC_VER
+  r = mkdir(buf);
+#else
+  r = mkdir(buf, 0700);
+#endif
+  if (r && errno != EEXIST)
     fprintf(stderr, "Can't create directory %s", buf);
 }