Преглед изворни кода

HTTP Upgrade: portability corrections

Evgeny Grin (Karlson2k) пре 9 година
родитељ
комит
a6458cd3a9

+ 2 - 1
configure.ac

@@ -558,7 +558,8 @@ fi
 AC_CHECK_HEADERS([fcntl.h math.h errno.h limits.h stdio.h locale.h sys/stat.h sys/types.h],,AC_MSG_ERROR([Compiling libmicrohttpd requires standard UNIX headers files]))
 
 # Check for optional headers
-AC_CHECK_HEADERS([sys/types.h sys/time.h sys/msg.h netdb.h netinet/in.h netinet/tcp.h time.h sys/socket.h sys/mman.h arpa/inet.h sys/select.h search.h \
+AC_CHECK_HEADERS([sys/types.h sys/time.h sys/msg.h time.h sys/mman.h search.h sys/ioctl.h \
+  sys/socket.h sys/select.h netdb.h netinet/in.h netinet/ip.h netinet/tcp.h arpa/inet.h \
   endian.h machine/endian.h sys/endian.h sys/param.h sys/machine.h sys/byteorder.h machine/param.h sys/isa_defs.h \
   inttypes.h stddef.h unistd.h \
   sockLib.h inetLib.h net/if.h])

+ 6 - 2
src/microhttpd/response.c

@@ -25,6 +25,11 @@
 
 #define MHD_NO_DEPRECATION 1
 
+#include "mhd_options.h"
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif /* HAVE_SYS_IOCTL_H */
+
 #include "internal.h"
 #include "response.h"
 #include "mhd_limits.h"
@@ -33,7 +38,6 @@
 #include "connection.h"
 #include "memorypool.h"
 
-#include <sys/ioctl.h>
 
 #if defined(_WIN32) && defined(MHD_W32_MUTEX_)
 #ifndef WIN32_LEAN_AND_MEAN
@@ -714,7 +718,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
     struct MemoryPool *pool;
     size_t avail;
     char *buf;
-    int sv[2];
+    MHD_socket sv[2];
 
     if (! MHD_socket_pair_ (sv))
     {

+ 3 - 3
src/microhttpd/test_upgrade.c

@@ -35,10 +35,10 @@
 #include <unistd.h>
 #endif
 
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
 #include "mhd_sockets.h"
+#ifdef HAVE_NETINET_IP_H
+#include <netinet/ip.h>
+#endif /* HAVE_NETINET_IP_H */
 #include "test_upgrade_common.c"
 
 

+ 9 - 2
src/microhttpd/test_upgrade_common.c

@@ -46,14 +46,15 @@ static pthread_t pt_client;
 static int done;
 
 /**
- * Change itc FD options to be non-blocking.
+ * Change socket to non-blocking.
  *
- * @param fd the FD to manipulate
+ * @param fd the socket to manipulate
  * @return non-zero if succeeded, zero otherwise
  */
 static void
 make_blocking (MHD_socket fd)
 {
+#if defined(MHD_POSIX_SOCKETS)
   int flags;
 
   flags = fcntl (fd, F_GETFL);
@@ -62,6 +63,12 @@ make_blocking (MHD_socket fd)
   if ((flags & ~O_NONBLOCK) != flags)
     if (-1 == fcntl (fd, F_SETFL, flags & ~O_NONBLOCK))
       abort ();
+#elif defined(MHD_WINSOCK_SOCKETS)
+  unsigned long flags = 1;
+
+  ioctlsocket (fd, FIONBIO, &flags);
+#endif /* MHD_WINSOCK_SOCKETS */
+
 }
 
 

+ 4 - 4
src/microhttpd/test_upgrade_ssl.c

@@ -34,12 +34,12 @@
 #include <unistd.h>
 #endif
 
-#include <sys/socket.h>
-#include <sys/wait.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
 #include <pthread.h>
 #include "mhd_sockets.h"
+#ifdef HAVE_NETINET_IP_H
+#include <netinet/ip.h>
+#endif /* HAVE_NETINET_IP_H */
+#include "mhd_sockets.h"
 #include "test_upgrade_common.c"
 
 #include "../testcurl/https/tls_test_keys.h"