3 Copyright (C) Andrew Tridgell 1999
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/>.
21 struct options options = {
22 .tcp_options = TCP_OPTIONS
25 static void server(int fd)
28 unsigned *ibuf = (unsigned *)buf;
31 signal(SIGPIPE, SIG_IGN);
33 printf("^"); fflush(stdout);
36 if (read_sock(fd, buf, 4) != 4) break;
38 if (n+4 >= sizeof(buf)) {
39 printf("overflow in server!\n");
42 if (read_sock(fd, buf+4, n) != (int)n) break;
45 if (write_sock(fd, buf, n+4) != (int)(n+4)) break;
51 static void listener(void)
55 sock = open_socket_in(SOCK_STREAM, TCP_PORT);
57 if (listen(sock, 20) == -1) {
58 fprintf(stderr,"listen failed\n");
62 printf("waiting for connections\n");
64 signal(SIGCHLD, SIG_IGN);
68 socklen_t in_addrlen = sizeof(addr);
71 while (waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0) ;
73 fd = accept(sock, &addr, &in_addrlen);
76 if (fork() == 0) server(fd);
83 static void usage(void)
85 printf("usage: tbench_srv [OPTIONS]\n"
87 " -t options set socket options\n");
92 static void process_opts(int argc, char **argv)
96 while ((c = getopt(argc, argv, "t:")) != -1) {
99 options.tcp_options = optarg;
108 int main(int argc, char *argv[])
110 process_opts(argc, argv);