+struct netio_options {
+ struct thread_data *td;
+ unsigned int port;
+ unsigned int proto;
+ unsigned int listen;
+};
+
+struct udp_close_msg {
+ uint32_t magic;
+ uint32_t cmd;
+};
+
+enum {
+ FIO_LINK_CLOSE = 0x89,
+ FIO_LINK_CLOSE_MAGIC = 0x6c696e6b,
+
+ FIO_TYPE_TCP = 1,
+ FIO_TYPE_UDP = 2,
+ FIO_TYPE_UNIX = 3,
+};
+
+static int str_hostname_cb(void *data, const char *input);
+static struct fio_option options[] = {
+ {
+ .name = "hostname",
+ .type = FIO_OPT_STR_STORE,
+ .cb = str_hostname_cb,
+ .help = "Hostname for net IO engine",
+ },
+ {
+ .name = "port",
+ .type = FIO_OPT_INT,
+ .off1 = offsetof(struct netio_options, port),
+ .minval = 1,
+ .maxval = 65535,
+ .help = "Port to use for TCP or UDP net connections",
+ },
+ {
+ .name = "protocol",
+ .alias = "proto",
+ .type = FIO_OPT_STR,
+ .off1 = offsetof(struct netio_options, proto),
+ .help = "Network protocol to use",
+ .def = "tcp",
+ .posval = {
+ { .ival = "tcp",
+ .oval = FIO_TYPE_TCP,
+ .help = "Transmission Control Protocol",
+ },
+ { .ival = "udp",
+ .oval = FIO_TYPE_UDP,
+ .help = "Unreliable Datagram Protocol",
+ },
+ { .ival = "unix",
+ .oval = FIO_TYPE_UNIX,
+ .help = "UNIX domain socket",
+ },
+ },
+ },
+ {
+ .name = "listen",
+ .type = FIO_OPT_STR_SET,
+ .off1 = offsetof(struct netio_options, listen),
+ .help = "Listen for incoming TCP connections",
+ },
+ {
+ .name = NULL,
+ },
+};
+
+/*
+ * Return -1 for error and 'nr events' for a positive number
+ * of events
+ */
+static int poll_wait(struct thread_data *td, int fd, short events)
+{
+ struct pollfd pfd;
+ int ret;
+
+ while (!td->terminate) {
+ pfd.fd = fd;
+ pfd.events = events;
+ ret = poll(&pfd, 1, -1);
+ if (ret < 0) {
+ if (errno == EINTR)
+ break;
+
+ td_verror(td, errno, "poll");
+ return -1;
+ } else if (!ret)
+ continue;
+
+ break;
+ }
+
+ if (pfd.revents & events)
+ return 1;
+
+ return -1;
+}
+