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 return fio_net_send_cmd(fio_client_fd, FIO_NET_CMD_JOB, buf, size);
64 * Send file contents to server backend. We could use sendfile(), but to remain
65 * more portable lets just read/write the darn thing.
67 int fio_client_send_ini(const char *filename)
74 fd = open(filename, O_RDONLY);
76 log_err("fio: job file open: %s\n", strerror(errno));
80 if (fstat(fd, &sb) < 0) {
81 log_err("fio: job file stat: %s\n", strerror(errno));
85 buf = malloc(sb.st_size);
90 ret = read(fd, p, len);
99 else if (errno == EAGAIN || errno == EINTR)
103 ret = send_file_buf(buf, sb.st_size);
108 int fio_handle_clients(void)
110 struct fio_net_cmd *cmd;
112 while (!exit_backend) {
113 cmd = fio_net_cmd_read(fio_client_fd);
117 if (cmd->opcode == FIO_NET_CMD_ACK) {
121 if (cmd->opcode == FIO_NET_CMD_QUIT) {
125 if (cmd->opcode != FIO_NET_CMD_TEXT) {
126 printf("non text: %d\n", cmd->opcode);
130 fwrite(cmd->payload, cmd->pdu_len, 1, stdout);