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 printf("cmd crc %x, pdu crc %x\n", cmd->cmd_crc32, cmd->pdu_crc32);
74 printf("job %x\n", cmd->opcode);
76 ret = fio_send_data(fio_client_fd, cmd, sizeof(*cmd) + size);
82 * Send file contents to server backend. We could use sendfile(), but to remain
83 * more portable lets just read/write the darn thing.
85 int fio_client_send_ini(const char *filename)
92 fd = open(filename, O_RDONLY);
94 log_err("fio: job file open: %s\n", strerror(errno));
98 if (fstat(fd, &sb) < 0) {
99 log_err("fio: job file stat: %s\n", strerror(errno));
103 buf = malloc(sb.st_size);
108 ret = read(fd, p, len);
117 else if (errno == EAGAIN || errno == EINTR)
121 ret = send_file_buf(buf, sb.st_size);