gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r9135 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r9135 - gnunet/src/util
Date: Thu, 8 Oct 2009 02:52:49 -0600

Author: grothoff
Date: 2009-10-08 02:52:48 -0600 (Thu, 08 Oct 2009)
New Revision: 9135

Modified:
   gnunet/src/util/network.c
Log:
check for FD_SETSIZE


Modified: gnunet/src/util/network.c
===================================================================
--- gnunet/src/util/network.c   2009-10-08 08:43:52 UTC (rev 9134)
+++ gnunet/src/util/network.c   2009-10-08 08:52:48 UTC (rev 9135)
@@ -31,6 +31,10 @@
 
 #define DEBUG_SOCK GNUNET_NO
 
+#ifndef INVALID_SOCKET
+#define INVALID_SOCKET -1
+#endif
+
 struct GNUNET_NETWORK_Handle
 {
   int fd;
@@ -68,10 +72,23 @@
 
   ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
   ret->fd = accept (desc->fd, address, address_len);
+  if (ret->fd == INVALID_SOCKET)
+    {
 #ifdef MINGW
-  if (INVALID_SOCKET == ret->fd)
-    SetErrnoFromWinsockError (WSAGetLastError ());
+      SetErrnoFromWinsockError (WSAGetLastError ());
 #endif
+      GNUNET_free (ret);
+      return NULL;
+    }
+#ifndef MINGW
+  if (ret->fd >= FD_SETSIZE)
+    {
+      close (desc->fd);
+      GNUNET_free (ret);
+      errno = EMFILE;
+      return NULL;
+    }
+#endif
   return ret;
 }
 
@@ -347,17 +364,23 @@
 
   ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
   ret->fd = socket (domain, type, protocol);
+  if (INVALID_SOCKET == ret->fd)
+    {
 #ifdef MINGW
-  if (INVALID_SOCKET == ret->fd)
-    SetErrnoFromWinsockError (WSAGetLastError ());
+      SetErrnoFromWinsockError (WSAGetLastError ());
 #endif
-
-  if (ret->fd < 0)
+      GNUNET_free (ret);
+      return NULL;
+    }
+#ifndef MINGW
+  if (ret->fd >= FD_SETSIZE)
     {
+      close (ret->fd);
       GNUNET_free (ret);
-      ret = NULL;
+      errno = EMFILE;
+      return NULL;
     }
-
+#endif
   return ret;
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]