annotate tests/test-accept4.c @ 15669:cf217ff25ff6

accept4 tests: Fix for native Windows. * tests/test-accept4.c: Include sockets.h. (main): Invoke gl_sockets_startup. * modules/accept4-tests (Depends-on): Add sockets.
author Bruno Haible <bruno@clisp.org>
date Tue, 20 Sep 2011 21:24:02 +0200
parents df1b2907db75
children 8250f2777afc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15649
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test accepting a connection to a server socket.
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2011 Free Software Foundation, Inc.
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <sys/socket.h>
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "signature.h"
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 SIGNATURE_CHECK (accept4, int, (int, struct sockaddr *, socklen_t *, int));
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <errno.h>
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <fcntl.h>
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <netinet/in.h>
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include "binary-io.h"
15669
cf217ff25ff6 accept4 tests: Fix for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 15649
diff changeset
29 #include "sockets.h"
15649
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #include "macros.h"
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 int
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 main (void)
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 {
15669
cf217ff25ff6 accept4 tests: Fix for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 15649
diff changeset
36 gl_sockets_startup (SOCKETS_1_1);
cf217ff25ff6 accept4 tests: Fix for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 15649
diff changeset
37
15649
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 /* Test behaviour for invalid file descriptors. */
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 {
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 struct sockaddr_in addr;
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 socklen_t addrlen = sizeof (addr);
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 errno = 0;
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 ASSERT (accept4 (-1, (struct sockaddr *) &addr, &addrlen,
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 O_CLOEXEC | O_BINARY)
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 == -1);
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 ASSERT (errno == EBADF);
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 }
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 {
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 struct sockaddr_in addr;
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 socklen_t addrlen = sizeof (addr);
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 errno = 0;
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 ASSERT (accept4 (99, (struct sockaddr *) &addr, &addrlen,
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 O_CLOEXEC | O_BINARY)
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 == -1);
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 ASSERT (errno == EBADF);
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 }
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 return 0;
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 }