annotate tests/test-accept4.c @ 17848:ab58d4870664

version-etc: new year * doc/gnulib.texi: * lib/version-etc.c (COPYRIGHT_YEAR): Update copyright date. * all files: Run 'make update-copyright'.
author Paul Eggert <eggert@cs.ucla.edu>
date Thu, 01 Jan 2015 01:38:23 +0000
parents 344018b6e5d7
children
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.
17848
ab58d4870664 version-etc: new year
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
2 Copyright (C) 2011-2015 Free Software Foundation, Inc.
15649
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>
17296
87f819736ab1 Fix typo in previous change, by including <unistd.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 17295
diff changeset
27 #include <unistd.h>
15649
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include "binary-io.h"
15669
cf217ff25ff6 accept4 tests: Fix for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 15649
diff changeset
30 #include "sockets.h"
15649
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #include "macros.h"
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 int
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 main (void)
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 {
16307
8c316b9e40cb tests: avoid spurious warnings about gl_sockets_startup
Jim Meyering <meyering@redhat.com>
parents: 16201
diff changeset
37 (void) gl_sockets_startup (SOCKETS_1_1);
15669
cf217ff25ff6 accept4 tests: Fix for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 15649
diff changeset
38
15649
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 /* Test behaviour for invalid file descriptors. */
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 {
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 struct sockaddr_in addr;
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 socklen_t addrlen = sizeof (addr);
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 errno = 0;
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 ASSERT (accept4 (-1, (struct sockaddr *) &addr, &addrlen,
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 O_CLOEXEC | O_BINARY)
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 == -1);
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 ASSERT (errno == EBADF);
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 {
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 struct sockaddr_in addr;
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 socklen_t addrlen = sizeof (addr);
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53
17295
3a09cc104f4c tests: don't assume fd 99 is closed
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
54 close (99);
15649
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 errno = 0;
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 ASSERT (accept4 (99, (struct sockaddr *) &addr, &addrlen,
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 O_CLOEXEC | O_BINARY)
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 == -1);
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 ASSERT (errno == EBADF);
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 }
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 return 0;
df1b2907db75 Tests for module 'accept4'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 }