This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <config.h>
19
20 #include <errno.h>
21 #include <stdbool.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <sys/time.h>
26 #include <sys/socket.h>
27
28 #if defined _WIN32 && ! defined __CYGWIN__
29 # include <process.h>
30 #else
31 # include <spawn.h>
32 #endif
33
34 #include "nonblocking.h"
35 #include "wait-process.h"
36
37 #include "macros.h"
38 #include "socket-server.h"
39 #include "test-nonblocking-socket.h"
40 #define PROG_ROLE "main"
41 #include "test-nonblocking-writer.h"
42
43 int
44 main (int argc, char *argv[])
45 {
46 const char *child_path;
47 int test;
48 int server;
49 int port;
50 pid_t child;
51 int server_socket;
52 int exitcode;
53
54 child_path = argv[1];
55 test = atoi (argv[2]);
56
57
58 server = create_server (0, 1, &port);
59
60
61 {
62 char port_arg[10+1];
63 const char *child_argv[4];
64
65 sprintf (port_arg, "%u", port);
66 child_argv[0] = child_path;
67 child_argv[1] = argv[2];
68 child_argv[2] = port_arg;
69 child_argv[3] = NULL;
70
71 #if defined _WIN32 && ! defined __CYGWIN__
72 child = _spawnvpe (P_NOWAIT, child_path, child_argv,
73 (const char **) environ);
74 ASSERT (child >= 0);
75 #else
76 {
77 pid_t child_pid;
78 int err =
79 posix_spawnp (&child_pid, child_path, NULL, NULL, (char **) child_argv,
80 environ);
81 ASSERT (err == 0);
82 child = child_pid;
83 }
84 #endif
85 }
86
87
88 server_socket = create_server_socket (server);
89
90
91 if (test & 1)
92 ASSERT (set_nonblocking_flag (server_socket, true) >= 0);
93
94 #if ENABLE_DEBUGGING
95 # ifdef SO_SNDBUF
96 {
97 int value;
98 socklen_t value_len = sizeof (value);
99 if (getsockopt (server_socket, SOL_SOCKET, SO_SNDBUF, &value, &value_len) >= 0)
100 fprintf (stderr, "SO_SNDBUF = %d\n", value);
101 }
102 # endif
103 # ifdef SO_RCVBUF
104 {
105 int value;
106 socklen_t value_len = sizeof (value);
107 if (getsockopt (server_socket, SOL_SOCKET, SO_RCVBUF, &value, &value_len) >= 0)
108 fprintf (stderr, "SO_RCVBUF = %d\n", value);
109 }
110 # endif
111 #endif
112
113 exitcode =
114 main_writer_loop (test, SOCKET_DATA_BLOCK_SIZE, server_socket,
115 SOCKET_HAS_LARGE_BUFFER);
116
117 {
118 int err =
119 wait_subprocess (child, child_path, false, false, false, false, NULL);
120 ASSERT (err == 0);
121 }
122
123 return exitcode;
124 }