gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r37769 - libmicrohttpd/src/microhttpd


From: gnunet
Subject: [GNUnet-SVN] r37769 - libmicrohttpd/src/microhttpd
Date: Tue, 23 Aug 2016 22:13:20 +0200

Author: Karlson2k
Date: 2016-08-23 22:13:19 +0200 (Tue, 23 Aug 2016)
New Revision: 37769

Modified:
   libmicrohttpd/src/microhttpd/daemon.c
   libmicrohttpd/src/microhttpd/mhd_sockets.h
Log:
mhd_sockets.h: added fd_set macros to use less '#ifdef' in code

Modified: libmicrohttpd/src/microhttpd/daemon.c
===================================================================
--- libmicrohttpd/src/microhttpd/daemon.c       2016-08-23 20:13:17 UTC (rev 
37768)
+++ libmicrohttpd/src/microhttpd/daemon.c       2016-08-23 20:13:19 UTC (rev 
37769)
@@ -650,22 +650,12 @@
               MHD_socket *max_fd,
               unsigned int fd_setsize)
 {
-  if (NULL == set)
+  if (NULL == set || MHD_INVALID_SOCKET == fd)
     return MHD_NO;
-#ifdef MHD_WINSOCK_SOCKETS
-  if (set->fd_count >= fd_setsize)
-    {
-      if (FD_ISSET(fd, set))
-        return MHD_YES;
-      else
-        return MHD_NO;
-    }
-#else  /* ! MHD_WINSOCK_SOCKETS */
-  if (fd >= (MHD_socket)fd_setsize)
+  if (!MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd, set, fd_setsize))
     return MHD_NO;
-#endif /* ! MHD_WINSOCK_SOCKETS */
-  FD_SET (fd, set);
-  if ( (NULL != max_fd) && (MHD_INVALID_SOCKET != fd) &&
+  MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd, set, fd_setsize);
+  if ( (NULL != max_fd) &&
        ((fd > *max_fd) || (MHD_INVALID_SOCKET == *max_fd)) )
     *max_fd = fd;
 
@@ -1325,15 +1315,14 @@
       return MHD_NO;
     }
 
-#ifndef MHD_WINSOCK_SOCKETS
-  if ( (client_socket >= FD_SETSIZE) &&
+  if ( (!MHD_SCKT_FD_FITS_FDSET_(client_socket, NULL)) &&
        (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) )
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
                "Socket descriptor larger than FD_SETSIZE: %d > %d\n",
-               client_socket,
-               FD_SETSIZE);
+               (int)client_socket,
+               (int)FD_SETSIZE);
 #endif
       if (0 != MHD_socket_close_ (client_socket))
        MHD_PANIC ("close failed\n");
@@ -1342,7 +1331,6 @@
 #endif
       return MHD_NO;
     }
-#endif
 
 
 #ifdef HAVE_MESSAGES
@@ -2267,7 +2255,7 @@
     {
       /* we're in epoll mode, the epoll FD stands for
         the entire event set! */
-      if (daemon->epoll_fd >= FD_SETSIZE)
+      if (!MHD_SCKT_FD_FITS_FDSET_(daemon->epoll_fd, NULL))
        return MHD_NO; /* poll fd too big, fail hard */
       if (FD_ISSET (daemon->epoll_fd, read_fd_set))
        return MHD_run (daemon);
@@ -3772,10 +3760,9 @@
       }
     make_nonblocking (daemon, daemon->wpipe[1]);
   }
-#ifndef MHD_WINSOCK_SOCKETS
   if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) &&
        (1 == use_pipe) &&
-       (daemon->wpipe[0] >= FD_SETSIZE) )
+       (!MHD_SCKT_FD_FITS_FDSET_(daemon->wpipe[0], NULL)) )
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
@@ -3788,7 +3775,6 @@
       free (daemon);
       return NULL;
     }
-#endif
 #ifdef DAUTH_SUPPORT
   daemon->digest_auth_rand_size = 0;
   daemon->digest_auth_random = NULL;
@@ -4131,8 +4117,7 @@
           goto free_and_fail;
         }
     }
-#ifndef MHD_WINSOCK_SOCKETS
-  if ( (socket_fd >= FD_SETSIZE) &&
+  if ( (!MHD_SCKT_FD_FITS_FDSET_(socket_fd, NULL)) &&
        (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY)) ) )
     {
 #ifdef HAVE_MESSAGES
@@ -4145,7 +4130,6 @@
        MHD_PANIC ("close failed\n");
       goto free_and_fail;
     }
-#endif
 
 #if EPOLL_SUPPORT
   if ( (0 != (flags & MHD_USE_EPOLL_LINUX_ONLY)) &&
@@ -4293,9 +4277,8 @@
                 }
               make_nonblocking (d, d->wpipe[1]);
             }
-#ifndef MHD_WINSOCK_SOCKETS
           if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) &&
-               (d->wpipe[0] >= FD_SETSIZE) )
+               (!MHD_SCKT_FD_FITS_FDSET_(d->wpipe[0], NULL)) )
             {
 #ifdef HAVE_MESSAGES
               MHD_DLOG (daemon,
@@ -4307,7 +4290,6 @@
                 MHD_PANIC ("close failed\n");
               goto thread_failed;
             }
-#endif
 
           /* Divide available connections evenly amongst the threads.
            * Thread indexes in [0, leftover_conns) each get one of the

Modified: libmicrohttpd/src/microhttpd/mhd_sockets.h
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_sockets.h  2016-08-23 20:13:17 UTC (rev 
37768)
+++ libmicrohttpd/src/microhttpd/mhd_sockets.h  2016-08-23 20:13:19 UTC (rev 
37769)
@@ -204,6 +204,53 @@
 #  define MHD_socket_close_(fd) closesocket((fd))
 #endif
 
+/**
+ * Check whether FD can be added to fd_set with specified FD_SETSIZE.
+ * @param fd   the fd to check
+ * @param pset the pointer to fd_set to check or NULL to check
+ *             whether FD can be used with fd_sets.
+ * @param setsize the value of FD_SETSIZE.
+ * @return boolean true if FD can be added to fd_set,
+ *         boolean false otherwise.
+ */
+#if defined(MHD_POSIX_SOCKETS)
+#  define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ((fd) < (setsize))
+#elif defined(MHD_WINSOCK_SOCKETS)
+#  define MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd,pset,setsize) ( 
((void*)(pset)==(void*)0) || \
+                                                             
(((fd_set*)(pset))->fd_count < (setsize)) || \
+                                                             
(FD_ISSET((fd),(pset))) )
+#endif
+
+/**
+ * Check whether FD can be added to fd_set with current FD_SETSIZE.
+ * @param fd   the fd to check
+ * @param pset the pointer to fd_set to check or NULL to check
+ *             whether FD can be used with fd_sets.
+ * @return boolean true if FD can be added to fd_set,
+ *         boolean false otherwise.
+ */
+#define MHD_SCKT_FD_FITS_FDSET_(fd,pset) 
MHD_SCKT_FD_FITS_FDSET_SETSIZE_((fd),(pset),FD_SETSIZE)
+
+/**
+ * Add FD to fd_set with specified FD_SETSIZE.
+ * @param fd   the fd to add
+ * @param pset the valid pointer to fd_set.
+ * @param setsize the value of FD_SETSIZE.
+ * @note  To work on W32 with value of FD_SETSIZE different from currently 
defined value,
+ *        system definition of FD_SET() is not used.
+ */
+#if defined(MHD_POSIX_SOCKETS)
+#  define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize) 
FD_SET((fd),(pset))
+#elif defined(MHD_WINSOCK_SOCKETS)
+#  define MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd,pset,setsize)                   
  \
+        do {                                                                   
  \
+           u_int _i_ = 0;                                                      
  \
+           fd_set* const _s_ = (fd_set*)(pset);                                
  \
+           while((_i_ < _s_->fd_count) && ((fd) != _s_->fd_array[_i_])) 
{++_i_;} \
+           if ((_i_ == _s_->fd_count)) {_s_->fd_array[_s_->fd_count++] = 
(fd);}  \
+        } while(0)
+#endif
+
  /* MHD_SYS_select_ is wrapper macro for system select() function */
 #if !defined(MHD_WINSOCK_SOCKETS)
 #  define MHD_SYS_select_(n,r,w,e,t) select((n),(r),(w),(e),(t))




reply via email to

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