12 #include <netinet/in.h>
13 #include <arpa/inet.h>
18 #include "crc/crc32.h"
20 int fio_client_fd = -1;
22 int fio_client_connect(const char *host)
24 struct sockaddr_in addr;
27 memset(&addr, 0, sizeof(addr));
28 addr.sin_family = AF_INET;
29 addr.sin_port = htons(fio_net_port);
31 if (inet_aton(host, &addr.sin_addr) != 1) {
34 hent = gethostbyname(host);
36 log_err("fio: gethostbyname: %s\n", strerror(errno));
40 memcpy(&addr.sin_addr, hent->h_addr, 4);
43 fd = socket(AF_INET, SOCK_STREAM, 0);
45 log_err("fio: socket: %s\n", strerror(errno));
49 if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
50 log_err("fio: connect: %s\n", strerror(errno));
58 static int send_file_buf(char *buf, off_t size)
60 struct fio_net_cmd *cmd;
63 cmd = malloc(sizeof(*cmd) + size);
65 fio_init_net_cmd(cmd);
66 cmd->opcode = cpu_to_le16(FIO_NET_CMD_JOB_END);
67 cmd->pdu_len = cpu_to_le32(size);
69 memcpy(&cmd->payload, buf, size);
73 ret = fio_send_data(fio_client_fd, cmd, sizeof(*cmd) + size);
79 * Send file contents to server backend. We could use sendfile(), but to remain
80 * more portable lets just read/write the darn thing.
82 int fio_client_send_ini(const char *filename)
89 fd = open(filename, O_RDONLY);
91 log_err("fio: job file open: %s\n", strerror(errno));
95 if (fstat(fd, &sb) < 0) {
96 log_err("fio: job file stat: %s\n", strerror(errno));
100 buf = malloc(sb.st_size);
105 ret = read(fd, p, len);
114 else if (errno == EAGAIN || errno == EINTR)
118 ret = send_file_buf(buf, sb.st_size);
123 int fio_handle_clients(void)
125 struct fio_net_cmd *cmd;
127 while (!exit_backend) {
128 cmd = fio_net_cmd_read(fio_client_fd);
132 if (cmd->opcode == FIO_NET_CMD_ACK) {
136 if (cmd->opcode != FIO_NET_CMD_TEXT) {
137 printf("non text: %d\n", cmd->opcode);
141 printf("%s", cmd->payload);