only update stats when we actually wrote sth, relevant for -n, ok djm
authorhenning <henning@openbsd.org>
Thu, 14 Aug 2008 22:29:43 +0000 (22:29 +0000)
committerhenning <henning@openbsd.org>
Thu, 14 Aug 2008 22:29:43 +0000 (22:29 +0000)
From: Pierre Riteau <pierre.riteau@gmail.com>

usr.bin/tcpbench/tcpbench.c

index 10709ef..bfb4440 100644 (file)
@@ -700,20 +700,22 @@ clientloop(kvm_t *kvmh, u_long ktcbtab, const char *host, const char *port,
                        err(1, "poll");
                }
                for (i = 0; i < nconn; i++) {
-                       if (pfd[i].revents & POLLOUT)
+                       if (pfd[i].revents & POLLOUT) {
                                if ((n = write(pfd[i].fd, buf, Bflag)) == -1) {
                                        if (errno == EINTR || errno == EAGAIN)
                                                continue;
                                        err(1, "write");
                                }
-                       if (n == 0) {
-                               warnx("Remote end closed connection");
-                               done = -1;
-                               break;
+                               if (n == 0) {
+                                       warnx("Remote end closed connection");
+                                       done = -1;
+                                       break;
+                               }
+                               if (vflag >= 3)
+                                       fprintf(stderr, "write: %zd bytes\n",
+                                           n);
+                               stats_update(&sc, n);
                        }
-                       if (vflag >= 3)
-                               fprintf(stderr, "write: %zd bytes\n", n);
-                       stats_update(&sc, n);
                }
        }
        stats_finish(&sc);
@@ -795,8 +797,7 @@ main(int argc, char **argv)
                                    errstr, optarg);
                        break;
                case 'v':
-                       if (vflag < 2)
-                               vflag++;
+                       vflag++;
                        break;
                case 'n':
                        nconn = strtonum(optarg, 0, 65535, &errstr);