[PATCH] Network io engine updates

- Use recv/send
- Set MSG_MORE on send if we are going to transmit more data
- Cleanups

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/engines/net.c b/engines/net.c
index 43026e5..222624d 100644
--- a/engines/net.c
+++ b/engines/net.c
@@ -48,18 +48,16 @@
 	struct net_data *nd = td->io_ops->data;
 	struct fio_file *f = io_u->file;
 
-	if (nd->send_to_net) {
-		if (io_u->ddir == DDIR_READ) {
-			td_verror(td, EINVAL);
-			return 1;
-		}
-	} else {
-		if (io_u->ddir == DDIR_WRITE) {
-			td_verror(td, EINVAL);
-			return 1;
-		}
+	/*
+	 * Make sure we don't see spurious reads to a receiver, and vice versa
+	 */
+	if ((nd->send_to_net && io_u->ddir == DDIR_READ) ||
+	    (!nd->send_to_net && io_u->ddir == DDIR_WRITE)) {
+		printf("boo!\n");
+		td_verror(td, EINVAL);
+		return 1;
 	}
-
+		
 	if (io_u->ddir == DDIR_SYNC)
 		return 0;
 	if (io_u->offset == f->last_completed_pos)
@@ -77,12 +75,23 @@
 {
 	struct net_data *nd = td->io_ops->data;
 	struct fio_file *f = io_u->file;
-	int ret = 0;
+	int ret;
 
-	if (io_u->ddir == DDIR_WRITE)
-		ret = write(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
-	else if (io_u->ddir == DDIR_READ)
-		ret = read(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
+	if (io_u->ddir == DDIR_WRITE) {
+		int flags = 0;
+
+		/*
+		 * if we are going to write more, set MSG_MORE
+		 */
+		if (td->this_io_bytes[DDIR_WRITE] + io_u->xfer_buflen <
+		    td->io_size)
+			flags = MSG_MORE;
+
+		ret = send(f->fd, io_u->xfer_buf, io_u->xfer_buflen, flags);
+	} else if (io_u->ddir == DDIR_READ)
+		ret = recv(f->fd, io_u->xfer_buf, io_u->xfer_buflen, MSG_WAITALL);
+	else
+		ret = 0;	/* must be a SYNC */
 
 	if (ret != (int) io_u->xfer_buflen) {
 		if (ret > 0) {
@@ -111,8 +120,9 @@
 	addr.sin_port = htons(port);
 
 	if (inet_aton(host, &addr.sin_addr) != 1) {
-		struct hostent *hent = gethostbyname(host);
+		struct hostent *hent;
 
+		hent = gethostbyname(host);
 		if (!hent) {
 			td_vmsg(td, errno, "gethostbyname");
 			return 1;
@@ -194,6 +204,11 @@
 	char *sep;
 	int ret, i;
 
+	if (!td->total_file_size) {
+		log_err("fio: need size= set\n");
+		return 1;
+	}
+
 	/*
 	 * work around for late init call
 	 */