round: ignore empty lines
[tools.git] / tools / spamnet.c
1 #include <jh.h>
2 #include <unistd.h>
3
4 int main(int argc, char **argv) {
5   if (argc != 4) xperror("invocation: <host> <port> <spamstr>", 0);
6   int s = netopen(argv[1], argv[2], JH_TCP_HINTS);
7   if (s < 0) {
8     fprintf(stderr, "unable to connect: %s\n", gai_strerror(s));
9     exit(1);
10   }
11   char *buf = argv[3];
12   ssize_t len = strlen(buf);
13   ssize_t total = 0;
14   while (1) {
15     ssize_t wcount = fail_on_neg(write(s, buf, len), "write failed", 1);
16     if (wcount == 0) {
17       fprintf(stderr, "zero write! ending.\n");
18       return 1;
19     }
20     if (wcount != len) {
21       fprintf(stderr, "wrong write size! ending.\n");
22       return 1;
23     }
24     total += wcount;
25     fprintf(stderr, "%zd\n", total);
26   }
27 }