]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Handle more errnos from accept() without closing the connection. This may fix a...
authorNick Mathewson <nickm@torproject.org>
Sun, 24 Oct 2004 00:55:18 +0000 (00:55 +0000)
committerNick Mathewson <nickm@torproject.org>
Sun, 24 Oct 2004 00:55:18 +0000 (00:55 +0000)
svn:r2579

src/common/util.h
src/or/connection.c

index 4d21f64bc19818dd70bd4e6b06a0102c4014e010..e4f0eaec5504cfb674912542903338c757dd59a2 100644 (file)
@@ -269,12 +269,22 @@ int parse_addr_and_port_range(const char *s, uint32_t *addr_out,
 /** Return true if e is EINPROGRESS or the local equivalent as returned by
  * a call to connect(). */
 #define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == WSAEINPROGRESS || (e)== WSAEINVAL)
+/** Return true if e is EAGAIN or another error indicating that a call to
+ * accept() has no pending connections to return. */
+#define ERRNO_IS_ACCEPT_EAGAIN(e)    ERRNO_IS_EAGAIN(e)
+/** Return true if e is EMFILE or another error indicating that a call to
+ * accept() has failed because we're out of fds or something. */
+#define ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e) \
+  ((e) == WSAEMFILE || (e) == WSAENOBUFS)
 int tor_socket_errno(int sock);
 const char *tor_socket_strerror(int e);
 #else
 #define ERRNO_IS_EAGAIN(e)           ((e) == EAGAIN)
 #define ERRNO_IS_EINPROGRESS(e)      ((e) == EINPROGRESS)
 #define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == EINPROGRESS)
+#define ERRNO_IS_ACCEPT_EAGAIN(e)    ((e) == EAGAIN || (e) == ECONNABORTED)
+#define ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e) \
+  ((e) == EMFILE || (e) == ENFILE || (e) == ENOBUFS || (e) == ENOMEM)
 #define tor_socket_errno(sock)       (errno)
 #define tor_socket_strerror(e)       strerror(e)
 #endif
index 477353b5f45b2ad04f099f63901fd07132db5679..0c8b9f74249d8381c25d24e4c131e6114e21ffa7 100644 (file)
@@ -385,11 +385,17 @@ static int connection_handle_listener_read(connection_t *conn, int new_type) {
 
   news = accept(conn->s,(struct sockaddr *)&remote,&remotelen);
   if (news == -1) { /* accept() error */
-    if(ERRNO_IS_EAGAIN(tor_socket_errno(conn->s))) {
+    int e = tor_socket_errno(conn->s);
+    if (ERRNO_IS_ACCEPT_EAGAIN(e)) {
       return 0; /* he hung up before we could accept(). that's fine. */
+    } else if (ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e)) {
+      log_fn(LOG_WARN,"accept failed: %s. Dropping incomming connection.",
+             tor_socket_strerror(e));
+      return 0;
     }
     /* else there was a real error. */
-    log_fn(LOG_WARN,"accept() failed. Closing listener.");
+    log_fn(LOG_WARN,"accept() failed: %s. Closing listener.", 
+           tor_socket_strerror(e));
     connection_mark_for_close(conn);
     return -1;
   }