tools/kq_connect_client: Use SOCK_NONBLOCK if it's available
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 30 Oct 2015 07:01:51 +0000 (15:01 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 30 Oct 2015 07:05:20 +0000 (15:05 +0800)
tools/tools/netrate/accept_connect/kq_connect_client/kq_connect_client.c

index ec0593a..6b1957c 100644 (file)
@@ -201,7 +201,9 @@ mainloop(const struct sockaddr_in *in, int in_cnt, int nconn_max,
        u_long count = 0;
        double time_us;
        u_int in_idx = 0;
+#ifndef SOCK_NONBLOCK
        int nblock = 1;
+#endif
 
        if (bindcpu) {
                int cpu = inst % cpucnt;
@@ -242,12 +244,18 @@ mainloop(const struct sockaddr_in *in, int in_cnt, int nconn_max,
                        if (do_udp)
                                udp_send(tmp);
 
+#ifndef SOCK_NONBLOCK
                        s = socket(AF_INET, SOCK_STREAM, 0);
                        if (s < 0)
                                err(1, "socket failed");
 
                        if (ioctl(s, FIONBIO, &nblock, sizeof(nblock)) < 0)
                                err(1, "ioctl failed");
+#else
+                       s = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
+                       if (s < 0)
+                               err(1, "socket failed");
+#endif
 
                        n = connect(s, (const struct sockaddr *)tmp,
                            sizeof(*tmp));