Fio 1.99.1
[fio.git] / server.c
index f586235fc1a44b16a6b3ae2f488410e38a0bf124..c4a0b7ef9b274613743e3405ef747aa388d16ae5 100644 (file)
--- a/server.c
+++ b/server.c
@@ -95,7 +95,7 @@ static int verify_convert_cmd(struct fio_net_cmd *cmd)
        cmd->pdu_len    = le32_to_cpu(cmd->pdu_len);
 
        switch (cmd->version) {
-       case FIO_SERVER_VER1:
+       case FIO_SERVER_VER2:
                break;
        default:
                log_err("fio: bad server cmd version %d\n", cmd->version);
@@ -113,7 +113,7 @@ static int verify_convert_cmd(struct fio_net_cmd *cmd)
 /*
  * Read (and defragment, if necessary) incoming commands
  */
-struct fio_net_cmd *fio_net_recv_cmd(int sk, int block)
+struct fio_net_cmd *fio_net_recv_cmd(int sk)
 {
        struct fio_net_cmd cmd, *cmdret = NULL;
        size_t cmd_size = 0, pdu_offset = 0;
@@ -122,37 +122,6 @@ struct fio_net_cmd *fio_net_recv_cmd(int sk, int block)
        void *pdu = NULL;
 
        do {
-               struct pollfd pfd;
-
-               pfd.fd = sk;
-               pfd.events = POLLIN;
-               ret = 0;
-               do {
-                       int timeo = block ? 100 : 10;
-
-                       ret = poll(&pfd, 1, timeo);
-                       if (ret < 0) {
-                               if (errno == EINTR)
-                                       break;
-                               log_err("fio: poll: %s\n", strerror(errno));
-                               break;
-                       } else if (!ret) {
-                               if (!block)
-                                       return NULL;
-                               continue;
-                       }
-
-                       if (pfd.revents & POLLIN)
-                               break;
-                       if (pfd.revents & (POLLERR|POLLHUP)) {
-                               ret = 1;
-                               break;
-                       }
-               } while (ret >= 0 && block);
-
-               if (ret < 0)
-                       break;
-
                ret = fio_recv_data(sk, &cmd, sizeof(cmd));
                if (ret)
                        break;
@@ -260,12 +229,9 @@ int fio_net_send_cmd(int fd, uint16_t opcode, const void *buf, off_t size)
 
 int fio_net_send_simple_cmd(int sk, uint16_t opcode, uint64_t serial)
 {
-       struct fio_net_cmd cmd = {
-               .version        = __cpu_to_le16(FIO_SERVER_VER1),
-               .opcode         = cpu_to_le16(opcode),
-               .serial         = cpu_to_le64(serial),
-       };
+       struct fio_net_cmd cmd;
 
+       fio_init_net_cmd(&cmd, opcode, NULL, 0);
        fio_net_cmd_crc(&cmd);
 
        return fio_send_data(sk, &cmd, sizeof(cmd));
@@ -376,7 +342,37 @@ static int handle_connection(int sk, int block)
 
        /* read forever */
        while (!exit_backend) {
-               cmd = fio_net_recv_cmd(sk, block);
+               struct pollfd pfd = {
+                       .fd     = sk,
+                       .events = POLLIN,
+               };
+
+               ret = 0;
+               do {
+                       ret = poll(&pfd, 1, 100);
+                       if (ret < 0) {
+                               if (errno == EINTR)
+                                       break;
+                               log_err("fio: poll: %s\n", strerror(errno));
+                               break;
+                       } else if (!ret) {
+                               if (!block)
+                                       return 0;
+                               continue;
+                       }
+
+                       if (pfd.revents & POLLIN)
+                               break;
+                       if (pfd.revents & (POLLERR|POLLHUP)) {
+                               ret = 1;
+                               break;
+                       }
+               } while (!exit_backend);
+
+               if (ret < 0)
+                       break;
+
+               cmd = fio_net_recv_cmd(sk);
                if (!cmd) {
                        ret = -1;
                        break;