X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-poll.c;h=7488090077925152591728677fef2f85f5b3603c;hb=9a09e8291d1bd692b26684c2bb7d9379593e8846;hp=cacb3a238f1c7b0abbd6cafaf85afbd08b70c676;hpb=f9f61e25aee8cf75e4cf084c66e82993dbf35c47;p=gnulib.git diff --git a/tests/test-poll.c b/tests/test-poll.c index cacb3a238..748809007 100644 --- a/tests/test-poll.c +++ b/tests/test-poll.c @@ -1,5 +1,5 @@ /* Test of poll() function. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,18 +19,29 @@ #include +#include + +#include "signature.h" +SIGNATURE_CHECK (poll, int, (struct pollfd[], nfds_t, int)); + #include #include #include #include #include -#include #include #include +#include +#include #include -#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,13 +50,11 @@ #include #endif -enum { FALSE, TRUE }; - #ifndef SO_REUSEPORT #define SO_REUSEPORT SO_REUSEADDR #endif -#define TEST_PORT 12345 +#define TEST_PORT 12345 /* Minimal testing infrastructure. */ @@ -87,7 +96,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 +126,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 +165,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 +223,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 +245,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,9 +270,9 @@ 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)) + != (POLLOUT | POLLWRNORM)) failed ("cannot write after blocking connect"); write (c, "foo", 3); wait (&pid); @@ -319,7 +324,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);