client: initial support for multiple connections
[fio.git] / server.h
... / ...
CommitLineData
1#ifndef FIO_SERVER_H
2#define FIO_SERVER_H
3
4#include <inttypes.h>
5#include <string.h>
6#include <endian.h>
7
8/*
9 * On-wire encoding is little endian
10 */
11struct fio_net_cmd {
12 uint16_t version; /* protocol version */
13 uint16_t opcode; /* command opcode */
14 uint32_t flags; /* modifier flags */
15 uint64_t serial; /* serial number */
16 uint32_t pdu_len; /* length of post-cmd layload */
17 uint16_t cmd_crc16; /* cmd checksum */
18 uint16_t pdu_crc16; /* payload checksum */
19 uint8_t payload[0]; /* payload */
20};
21
22enum {
23 FIO_SERVER_VER = 1,
24 FIO_SERVER_VER1 = 1,
25
26 FIO_SERVER_MAX_PDU = 64,
27
28 FIO_NET_CMD_QUIT = 1,
29 FIO_NET_CMD_JOB = 2,
30 FIO_NET_CMD_ACK = 3,
31 FIO_NET_CMD_NAK = 4,
32 FIO_NET_CMD_TEXT = 5,
33
34 FIO_NET_CMD_F_MORE = 1,
35
36 /* crc does not include the crc fields */
37 FIO_NET_CMD_CRC_SZ = sizeof(struct fio_net_cmd) -
38 2 * sizeof(uint16_t),
39};
40
41extern int fio_server(void);
42extern int fio_server_text_output(const char *, unsigned int len);
43extern int fio_server_log(const char *format, ...);
44extern int fio_net_send_cmd(int, uint16_t, const char *, off_t);
45
46extern int fio_client_connect(const char *);
47extern int fio_client_send_ini(const char *, const char *);
48extern int fio_handle_clients(void);
49
50extern int fio_recv_data(int sk, void *p, unsigned int len);
51extern int fio_send_data(int sk, const void *p, unsigned int len);
52extern void fio_net_cmd_crc(struct fio_net_cmd *);
53extern struct fio_net_cmd *fio_net_cmd_read(int sk);
54
55extern int exit_backend;
56extern int fio_net_port;
57
58#if __BYTE_ORDER == __LITTLE_ENDIAN
59#define le16_to_cpu(x) (x)
60#define le32_to_cpu(x) (x)
61#define le64_to_cpu(x) (x)
62#define cpu_to_le16(x) (x)
63#define cpu_to_le32(x) (x)
64#define cpu_to_le64(x) (x)
65#elif __BYTE_ORDER == __BIG_ENDIAN
66#define le16_to_cpu(x) __bswap_16(x)
67#define le32_to_cpu(x) __bswap_32(x)
68#define le64_to_cpu(x) __bswap_64(x)
69#define cpu_to_le16(x) __bswap_16(x)
70#define cpu_to_le32(x) __bswap_32(x)
71#define cpu_to_le64(x) __bswap_64(x)
72#else
73#error "Endianness not detected"
74#endif
75
76static inline void fio_init_net_cmd(struct fio_net_cmd *cmd, uint16_t opcode,
77 const void *pdu, uint32_t pdu_len)
78{
79 memset(cmd, 0, sizeof(*cmd));
80
81 cmd->version = cpu_to_le16(FIO_SERVER_VER1);
82 cmd->opcode = cpu_to_le16(opcode);
83
84 if (pdu) {
85 cmd->pdu_len = cpu_to_le32(pdu_len);
86 memcpy(&cmd->payload, pdu, pdu_len);
87 }
88}
89
90#endif