server: ensure payload larger than max is broken into pieces
[fio.git] / client.c
index c94ccf3fa213ff50c6bfcf9792c9e617bb742cf9..1074da446be7839a9f40f2d21419504286f69140 100644 (file)
--- a/client.c
+++ b/client.c
@@ -57,25 +57,7 @@ int fio_client_connect(const char *host)
 
 static int send_file_buf(char *buf, off_t size)
 {
-       struct fio_net_cmd *cmd;
-       int ret;
-
-       cmd = malloc(sizeof(*cmd) + size);
-
-       fio_init_net_cmd(cmd);
-       cmd->opcode     = cpu_to_le16(FIO_NET_CMD_JOB_END);
-       cmd->pdu_len    = cpu_to_le32(size);
-
-       memcpy(&cmd->payload, buf, size);
-
-       fio_net_cmd_crc(cmd);
-
-       printf("cmd crc %x, pdu crc %x\n", cmd->cmd_crc32, cmd->pdu_crc32);
-       printf("job %x\n", cmd->opcode);
-
-       ret = fio_send_data(fio_client_fd, cmd, sizeof(*cmd) + size);
-       free(cmd);
-       return ret;
+       return fio_net_send_cmd(fio_client_fd, FIO_NET_CMD_JOB, buf, size);
 }
 
 /*
@@ -122,3 +104,33 @@ int fio_client_send_ini(const char *filename)
        free(buf);
        return ret;
 }
+
+int fio_handle_clients(void)
+{
+       struct fio_net_cmd *cmd;
+
+       while (!exit_backend) {
+               cmd = fio_net_cmd_read(fio_client_fd);
+               if (!cmd)
+                       continue;
+
+               if (cmd->opcode == FIO_NET_CMD_ACK) {
+                       free(cmd);
+                       continue;
+               }
+               if (cmd->opcode == FIO_NET_CMD_QUIT) {
+                       free(cmd);
+                       break;
+               }
+               if (cmd->opcode != FIO_NET_CMD_TEXT) {
+                       printf("non text: %d\n", cmd->opcode);
+                       free(cmd);
+                       continue;
+               }
+               fwrite(cmd->payload, cmd->pdu_len, 1, stdout);
+               fflush(stdout);
+               free(cmd);
+       }
+
+       return 0;
+}