cleanup zombies during run, and check processes still exist
[tridge/junkcode.git] / sock_sink.c
1 #include "socklib.h"
2
3
4 static char *tcp_options="";
5 static int port=7001;
6 static int bufsize=8192;
7 static char *host;
8
9 static void sender(void)
10 {
11         int fd, total=0;
12         char *buf;
13         
14         fd = open_socket_out(host, port);
15
16         set_socket_options(fd, tcp_options);
17
18         buf = (char *)malloc(bufsize);
19
20         if (!buf) {
21                 fprintf(stderr,"out of memory\n");
22                 exit(1);
23         }
24
25         memset(buf, 'Z', bufsize);
26
27         start_timer();
28
29         while (1) {
30                 int ret = read(fd, buf, bufsize);
31                 if (ret <= 0) break;
32                 total += ret;
33                 if (end_timer() > 2.0) {
34                         report_time(total);
35                         printf("%g MB\n", total*1.0e-6);
36                         total = 0;
37                         start_timer();
38                 }
39         }
40 }
41
42
43 static void usage(void)
44 {
45         printf("-p port\n-t socket options\n-H host\n-b bufsize\n\n");
46 }
47
48 int main(int argc, char *argv[])
49 {
50         int opt;
51         extern char *optarg;
52
53         while ((opt = getopt (argc, argv, "p:t:H:b:h")) != EOF) {
54                 switch (opt) {
55                 case 'p':
56                         port = atoi(optarg);
57                         break;
58                 case 't':
59                         tcp_options = optarg;
60                         break;
61                 case 'H':
62                         host = optarg;
63                         break;
64                 case 'b':
65                         bufsize = atoi(optarg);
66                         break;
67
68                 case 'h':
69                 default:
70                         usage();
71                         exit(1);
72                 }
73         }
74
75         printf("host=%s port=%d options=[%s]\n", host, port, tcp_options);
76
77         sender();
78
79         return 0;
80 }