[or-cvs] simplify code now that libevent considers all sockets polla...

arma at seul.org arma at seul.org
Mon Jun 5 09:07:02 UTC 2006


Update of /home2/or/cvsroot/tor/src/common
In directory moria:/home/arma/work/onion/cvs/tor/src/common

Modified Files:
	compat.c compat.h 
Log Message:
simplify code now that libevent considers all sockets pollable.
what we really mean now is ">= 0", which is clearer to test for.


Index: compat.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/compat.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -p -d -r1.89 -r1.90
--- compat.c	4 Jun 2006 22:42:12 -0000	1.89
+++ compat.c	5 Jun 2006 09:07:00 -0000	1.90
@@ -415,17 +415,8 @@ tor_socketpair(int family, int type, int
     }
 
     listener = socket(AF_INET, type, 0);
-    if (listener == -1)
+    if (listener < 0)
       return -tor_socket_errno(-1);
-    if (!SOCKET_IS_POLLABLE(listener)) {
-      log_warn(LD_NET, "Too many connections; can't open socketpair");
-      tor_close_socket(listener);
-#ifdef MS_WINDOWS
-      return -ENFILE;
-#else
-      return -ENCONN;
-#endif
-    }
     memset(&listen_addr, 0, sizeof(listen_addr));
     listen_addr.sin_family = AF_INET;
     listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
@@ -437,12 +428,8 @@ tor_socketpair(int family, int type, int
       goto tidy_up_and_fail;
 
     connector = socket(AF_INET, type, 0);
-    if (connector == -1)
-      goto tidy_up_and_fail;
-    if (!SOCKET_IS_POLLABLE(connector)) {
-      log_warn(LD_NET, "Too many connections; can't open socketpair");
+    if (connector < 0)
       goto tidy_up_and_fail;
-    }
     /* We want to find out the port number to connect to.  */
     size = sizeof(connect_addr);
     if (getsockname(listener, (struct sockaddr *) &connect_addr, &size) == -1)
@@ -455,12 +442,8 @@ tor_socketpair(int family, int type, int
 
     size = sizeof(listen_addr);
     acceptor = accept(listener, (struct sockaddr *) &listen_addr, &size);
-    if (acceptor == -1)
-      goto tidy_up_and_fail;
-    if (!SOCKET_IS_POLLABLE(acceptor)) {
-      log_warn(LD_NET, "Too many connections; can't open socketpair");
+    if (acceptor < 0)
       goto tidy_up_and_fail;
-    }
     if (size != sizeof(listen_addr))
       goto abort_tidy_up_and_fail;
     tor_close_socket(listener);

Index: compat.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/compat.h,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -p -d -r1.47 -r1.48
--- compat.h	3 Jun 2006 18:52:31 -0000	1.47
+++ compat.h	5 Jun 2006 09:07:00 -0000	1.48
@@ -175,10 +175,6 @@ int touch_file(const char *fname);
 typedef int socklen_t;
 #endif
 
-/* Now that we use libevent, all real sockets are safe for polling ... or
- * if they aren't, libevent will help us. */
-#define SOCKET_IS_POLLABLE(fd) ((fd)>=0)
-
 struct in_addr;
 int tor_inet_aton(const char *cp, struct in_addr *addr);
 int tor_lookup_hostname(const char *name, uint32_t *addr);



More information about the tor-commits mailing list