#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
static unsigned int job_cur_len;
static unsigned int job_max_len;
+static int server_fd;
+
int fio_send_data(int sk, const void *p, unsigned int len)
{
do {
return 0;
}
-static struct fio_net_cmd *read_command(int sk)
+struct fio_net_cmd *fio_net_cmd_read(int sk)
{
struct fio_net_cmd cmd, *ret = NULL;
uint32_t crc;
return NULL;
}
-
return ret;
}
/* read forever */
while (!exit_backend) {
- cmd = read_command(sk);
+ cmd = fio_net_cmd_read(sk);
if (!cmd) {
ret = 1;
break;
return -1;
}
+ server_fd = sk;
+
exitval = handle_connection(sk);
+ server_fd = -1;
close(sk);
if (!exit_backend)
close(sk);
return ret;
}
+
+int fio_server_text_output(const char *buf, unsigned int len)
+{
+ struct fio_net_cmd *cmd;
+ int size = sizeof(*cmd) + 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, 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);
+}