server: debug fixes
[fio.git] / server.c
index 1749e7365bb446076366ad50f6a0db4c8a7be81d..79c10410a316b05a21ccd83241e529bfa91e24f3 100644 (file)
--- a/server.c
+++ b/server.c
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdarg.h>
 #include <unistd.h>
 #include <limits.h>
 #include <errno.h>
@@ -142,7 +143,6 @@ struct fio_net_cmd *fio_net_cmd_read(int sk)
                return NULL;
        }
 
-
        return ret;
 }
 
@@ -367,18 +367,29 @@ int fio_server(void)
        return ret;
 }
 
-void fio_server_text_output(const char *buf, unsigned int len)
+int fio_server_text_output(const char *buf, unsigned int len)
 {
        struct fio_net_cmd *cmd;
+       int size = sizeof(*cmd) + len;
 
-       cmd = malloc(sizeof(*cmd) + len);
-       fio_init_net_cmd(cmd);
-       cmd->opcode     = cpu_to_le16(FIO_NET_CMD_TEXT);
-       cmd->pdu_len    = cpu_to_le32(len);
-       memcpy(&cmd->payload, buf, len);
-
+       cmd = malloc(size);
+       fio_init_net_cmd(cmd, FIO_NET_CMD_TEXT, buf, len);
        fio_net_cmd_crc(cmd);
 
-       fio_send_data(server_fd, cmd, sizeof(*cmd) + len);
+       fio_send_data(server_fd, cmd, size);
        free(cmd);
+       return size;
+}
+
+int fio_server_log(const char *format, ...)
+{
+       char buffer[1024];
+       va_list args;
+       size_t len;
+
+       va_start(args, format);
+       len = vsnprintf(buffer, sizeof(buffer), format, args);
+       va_end(args);
+
+       return fio_server_text_output(buffer, len);
 }