net: set runstate to SETTING_UP while waiting for a connection
[fio.git] / engines / net.c
index 6748a3e2b65a1185c76260d085c64d99bc11e1b9..373821b2142bb8d3a7428179d4c4218ff05118e1 100644 (file)
@@ -79,7 +79,7 @@ static struct fio_option options[] = {
                          },
                          { .ival = "udp",
                            .oval = FIO_TYPE_UDP,
-                           .help = "Unreliable Datagram Protocol",
+                           .help = "User Datagram Protocol",
                          },
                          { .ival = "unix",
                            .oval = FIO_TYPE_UNIX,
@@ -144,7 +144,7 @@ static int fio_netio_prep(struct thread_data *td, struct io_u *io_u)
                td_verror(td, EINVAL, "bad direction");
                return 1;
        }
-               
+
        return 0;
 }
 
@@ -360,6 +360,8 @@ static int fio_netio_recv(struct thread_data *td, struct io_u *io_u)
                }
                if (ret > 0)
                        break;
+               else if (!ret && (flags & MSG_WAITALL))
+                       break;
 
                ret = poll_wait(td, io_u->file->fd, POLLIN);
                if (ret <= 0)
@@ -473,24 +475,32 @@ static int fio_netio_accept(struct thread_data *td, struct fio_file *f)
        struct netio_data *nd = td->io_ops->data;
        struct netio_options *o = td->eo;
        fio_socklen_t socklen = sizeof(nd->addr);
+       int state;
 
        if (o->proto == FIO_TYPE_UDP) {
                f->fd = nd->listenfd;
                return 0;
        }
 
+       state = td->runstate;
+       td_set_runstate(td, TD_SETTING_UP);
+
        log_info("fio: waiting for connection\n");
 
        if (poll_wait(td, nd->listenfd, POLLIN) < 0)
-               return 1;
+               goto err;
 
        f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr, &socklen);
        if (f->fd < 0) {
                td_verror(td, errno, "accept");
-               return 1;
+               goto err;
        }
 
+       td_set_runstate(td, state);
        return 0;
+err:
+       td_set_runstate(td, state);
+       return 1;
 }
 
 static int fio_netio_open_file(struct thread_data *td, struct fio_file *f)
@@ -543,6 +553,15 @@ static int fio_netio_setup_connect_inet(struct thread_data *td,
 {
        struct netio_data *nd = td->io_ops->data;
 
+       if (!host) {
+               log_err("fio: connect with no host to connect to.\n");
+               if (td_read(td))
+                       log_err("fio: did you forget to set 'listen'?\n");
+
+               td_verror(td, EINVAL, "no hostname= set");
+               return 1;
+       }
+
        nd->addr.sin_family = AF_INET;
        nd->addr.sin_port = htons(port);
 
@@ -687,6 +706,11 @@ static int fio_netio_init(struct thread_data *td)
        struct netio_options *o = td->eo;
        int ret;
 
+#ifdef WIN32
+       WSADATA wsd;
+       WSAStartup(MAKEWORD(2,2), &wsd);
+#endif
+
        if (td_random(td)) {
                log_err("fio: network IO can't be random\n");
                return 1;
@@ -702,13 +726,17 @@ static int fio_netio_init(struct thread_data *td)
 
        if (o->proto != FIO_TYPE_TCP) {
                if (o->listen) {
-                         log_err("fio: listen only valid for TCP proto IO\n");
-                         return 1;
+                       log_err("fio: listen only valid for TCP proto IO\n");
+                       return 1;
                }
                if (td_rw(td)) {
-                         log_err("fio: datagram network connections must be"
+                       log_err("fio: datagram network connections must be"
                                   " read OR write\n");
-                         return 1;
+                       return 1;
+               }
+               if (o->proto == FIO_TYPE_UNIX && !td->o.filename) {
+                       log_err("fio: UNIX sockets need host/filename\n");
+                       return 1;
                }
                o->listen = td_read(td);
        }