junk code import
[tridge/junkcode.git] / socklib / 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                         total = 0;
36                         start_timer();
37                 }
38         }
39 }
40
41
42 static void usage(void)
43 {
44         printf("-p port\n-t socket options\n-H host\n-b bufsize\n\n");
45 }
46
47 int main(int argc, char *argv[])
48 {
49         int opt;
50         extern char *optarg;
51
52         while ((opt = getopt (argc, argv, "p:t:H:b:h")) != EOF) {
53                 switch (opt) {
54                 case 'p':
55                         port = atoi(optarg);
56                         break;
57                 case 't':
58                         tcp_options = optarg;
59                         break;
60                 case 'H':
61                         host = optarg;
62                         break;
63                 case 'b':
64                         bufsize = atoi(optarg);
65                         break;
66
67                 case 'h':
68                 default:
69                         usage();
70                         exit(1);
71                 }
72         }
73
74         printf("host=%s port=%d options=[%s]\n", host, port, tcp_options);
75
76         sender();
77
78         return 0;
79 }