+ goto err;
+ }
+
+ reset_all_stats(td);
+ td_set_runstate(td, state);
+ return 0;
+err:
+ td_set_runstate(td, state);
+ return 1;
+}
+
+static void fio_netio_udp_close(struct thread_data *td, struct fio_file *f)
+{
+ struct netio_data *nd = td->io_ops->data;
+ struct udp_close_msg msg;
+ struct sockaddr *to = (struct sockaddr *) &nd->addr;
+ int ret;
+
+ msg.magic = htonl(FIO_LINK_OPEN_CLOSE_MAGIC);
+ msg.cmd = htonl(FIO_LINK_CLOSE);
+
+ ret = sendto(f->fd, (void *) &msg, sizeof(msg), MSG_WAITALL, to,
+ sizeof(nd->addr));
+ if (ret < 0)
+ td_verror(td, errno, "sendto udp link close");
+}
+
+static int fio_netio_close_file(struct thread_data *td, struct fio_file *f)
+{
+ struct netio_options *o = td->eo;
+
+ /*
+ * If this is an UDP connection, notify the receiver that we are
+ * closing down the link
+ */
+ if (o->proto == FIO_TYPE_UDP)
+ fio_netio_udp_close(td, f);
+
+ return generic_close_file(td, f);
+}
+
+static int fio_netio_udp_recv_open(struct thread_data *td, struct fio_file *f)
+{
+ struct netio_data *nd = td->io_ops->data;
+ struct udp_close_msg msg;
+ struct sockaddr *to = (struct sockaddr *) &nd->addr;
+ socklen_t len = sizeof(nd->addr);
+ int ret;
+
+ ret = recvfrom(f->fd, (void *) &msg, sizeof(msg), MSG_WAITALL, to, &len);
+ if (ret < 0) {
+ td_verror(td, errno, "sendto udp link open");
+ return ret;
+ }
+
+ if (ntohl(msg.magic) != FIO_LINK_OPEN_CLOSE_MAGIC ||
+ ntohl(msg.cmd) != FIO_LINK_OPEN) {
+ log_err("fio: bad udp open magic %x/%x\n", ntohl(msg.magic),
+ ntohl(msg.cmd));
+ return -1;
+ }
+
+ return 0;
+}
+
+static int fio_netio_udp_send_open(struct thread_data *td, struct fio_file *f)
+{
+ struct netio_data *nd = td->io_ops->data;
+ struct udp_close_msg msg;
+ struct sockaddr *to = (struct sockaddr *) &nd->addr;
+ int ret;
+
+ msg.magic = htonl(FIO_LINK_OPEN_CLOSE_MAGIC);
+ msg.cmd = htonl(FIO_LINK_OPEN);
+
+ ret = sendto(f->fd, (void *) &msg, sizeof(msg), MSG_WAITALL, to,
+ sizeof(nd->addr));
+ if (ret < 0) {
+ td_verror(td, errno, "sendto udp link open");
+ return ret;