environ is supposed to be declared by <unistd.h>.
[gnulib.git] / tests / test-poll.c
index 1f66a63..77b06d9 100644 (file)
 #include <fcntl.h>
 #include <stdlib.h>
 #include <stdbool.h>
+#include <sys/ioctl.h>
 #include <errno.h>
 #include "sockets.h"
 
-#ifdef __MSVCRT__
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# define WIN32_NATIVE
+#endif
+
+#ifdef WIN32_NATIVE
 #include <io.h>
 #define pipe(x) _pipe(x, 256, O_BINARY)
 #endif
@@ -123,28 +128,24 @@ connect_to_socket (int blocking)
 
   if (!blocking)
     {
-#ifdef __MSVCRT__
+#ifdef WIN32_NATIVE
       unsigned long iMode = 1;
-      ioctlsocket (s, FIONBIO, (void *) &iMode);
+      ioctl (s, FIONBIO, (char *) &iMode);
+
 #elif defined F_GETFL
       int oldflags = fcntl (s, F_GETFL, NULL);
+
       if (!(oldflags & O_NONBLOCK))
         fcntl (s, F_SETFL, oldflags | O_NONBLOCK);
 #endif
     }
 
-  if (connect (s, (struct sockaddr *) &ia, sizeof (ia)) < 0)
+  if (connect (s, (struct sockaddr *) &ia, sizeof (ia)) < 0
+      && (blocking || errno != EINPROGRESS))
     {
-      if (errno != EINPROGRESS)
-       {
-         perror ("connect");
-         exit (77);
-       }
+      perror ("connect");
+      exit (77);
     }
-  else if (!blocking)
-    failed ("huh, connect succeeded?");
 
   return s;
 }
@@ -161,7 +162,7 @@ poll1 (int fd, int ev, int time)
   pfd.fd = fd;
   pfd.events = ev;
   pfd.revents = 0;
-  r = poll (&pfd, 1, time);  
+  r = poll (&pfd, 1, time);
   if (r < 0)
     return r;
 
@@ -241,7 +242,7 @@ test_connect_first (void)
 static void
 test_accept_first (void)
 {
-#ifndef __MSVCRT__
+#ifndef WIN32_NATIVE
   int s = open_server_socket ();
   struct sockaddr_in ia;
   socklen_t addrlen;
@@ -359,7 +360,7 @@ main ()
 {
   int result;
 
-  gl_sockets_startup (SOCKETS_2_0);
+  gl_sockets_startup (SOCKETS_1_1);
 
 #ifdef INTERACTIVE
   printf ("Please press Enter\n");