1 /* Test for nonblocking read and write on sockets.
3 Copyright (C) 2011 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include <sys/socket.h>
28 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
34 #include "nonblocking.h"
35 #include "wait-process.h"
38 #include "socket-server.h"
39 #include "test-nonblocking-socket.h"
40 #define PROG_ROLE "main"
41 #include "test-nonblocking-writer.h"
44 main (int argc, char *argv[])
46 const char *child_path = argv[1];
47 int test = atoi (argv[2]);
54 /* Create a server socket. */
55 server = create_server (0, 1, &port);
57 /* Spawn the child process. */
60 const char *child_argv[4];
62 sprintf (port_arg, "%u", port);
63 child_argv[0] = child_path;
64 child_argv[1] = argv[2];
65 child_argv[2] = port_arg;
68 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
69 child = spawnvpe (P_NOWAIT, child_path, child_argv,
70 (const char **) environ);
76 posix_spawnp (&child_pid, child_path, NULL, NULL, (char **) child_argv,
84 /* Accept a connection from the child process. */
85 server_socket = create_server_socket (server);
87 /* Prepare the file descriptor. */
89 ASSERT (set_nonblocking_flag (server_socket, true) >= 0);
95 socklen_t value_len = sizeof (value);
96 if (getsockopt (server_socket, SOL_SOCKET, SO_SNDBUF, &value, &value_len) >= 0)
97 fprintf (stderr, "SO_SNDBUF = %d\n", value);
103 socklen_t value_len = sizeof (value);
104 if (getsockopt (server_socket, SOL_SOCKET, SO_RCVBUF, &value, &value_len) >= 0)
105 fprintf (stderr, "SO_RCVBUF = %d\n", value);
111 main_writer_loop (test, SOCKET_DATA_BLOCK_SIZE, server_socket,
112 SOCKET_HAS_LARGE_BUFFER);
116 wait_subprocess (child, child_path, false, false, false, false, NULL);