X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-poll.c;h=bbfefe43e0047848cac5ccc34142a333c8ea13e0;hb=9c9a9765811eb1e698517065953e09d6b8c07400;hp=cacb3a238f1c7b0abbd6cafaf85afbd08b70c676;hpb=f9f61e25aee8cf75e4cf084c66e82993dbf35c47;p=gnulib.git diff --git a/tests/test-poll.c b/tests/test-poll.c index cacb3a238..bbfefe43e 100644 --- a/tests/test-poll.c +++ b/tests/test-poll.c @@ -27,10 +27,17 @@ #include #include #include +#include #include +#include "sockets.h" -#ifdef HAVE_IO_H +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +# define WIN32_NATIVE +#endif + +#ifdef WIN32_NATIVE #include +#define pipe(x) _pipe(x, 256, O_BINARY) #endif #ifdef HAVE_UNISTD_H #include @@ -39,8 +46,6 @@ #include #endif -enum { FALSE, TRUE }; - #ifndef SO_REUSEPORT #define SO_REUSEPORT SO_REUSEADDR #endif @@ -87,7 +92,7 @@ open_server_socket () memset (&ia, 0, sizeof (ia)); ia.sin_family = AF_INET; - inet_aton ("127.0.0.1", &ia.sin_addr); + inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr); ia.sin_port = htons (TEST_PORT); if (bind (s, (struct sockaddr *) &ia, sizeof (ia)) < 0) { @@ -117,33 +122,29 @@ connect_to_socket (int blocking) memset (&ia, 0, sizeof (ia)); ia.sin_family = AF_INET; - inet_aton ("127.0.0.1", &ia.sin_addr); + inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr); ia.sin_port = htons (TEST_PORT); if (!blocking) { -#ifdef __MSVCRT__ +#ifdef WIN32_NATIVE unsigned long iMode = 1; - ioctl (s, FIONBIO, &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; } @@ -160,7 +161,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; @@ -218,7 +219,7 @@ test_connect_first (void) if (poll1_nowait (s, POLLIN | POLLRDNORM | POLLRDBAND) != 0) failed ("can read, socket not connected"); - c1 = connect_to_socket (FALSE); + c1 = connect_to_socket (false); if (poll1_wait (s, POLLIN | POLLRDNORM | POLLRDBAND) != (POLLIN | POLLRDNORM)) failed ("expecting POLLIN | POLLRDNORM on passive socket"); @@ -240,7 +241,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; @@ -265,7 +266,7 @@ test_accept_first (void) else { close (s); - c = connect_to_socket (TRUE); + c = connect_to_socket (true); if (poll1_nowait (c, POLLOUT | POLLWRNORM | POLLRDBAND) != (POLLOUT | POLLWRNORM)) failed ("cannot write after blocking connect"); @@ -319,7 +320,7 @@ test_socket_pair (void) socklen_t addrlen = sizeof (ia); int s = open_server_socket (); - int c1 = connect_to_socket (FALSE); + int c1 = connect_to_socket (false); int c2 = accept (s, (struct sockaddr *) &ia, &addrlen); close (s); @@ -358,6 +359,8 @@ main () { int result; + gl_sockets_startup (SOCKETS_1_1); + #ifdef INTERACTIVE printf ("Please press Enter\n"); test (test_tty, "TTY");