socket-handler: only send if the queue is empty

If we're able to do a non-blocking send (but haven't yet received the
POLLOUT event), then we may end up sending data out-of-order.

This change only attempts a write if we have nothing in the queue.

Change-Id: Ie207ee10cdee27731dab30474bbdbafb51c31760
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
diff --git a/socket-handler.c b/socket-handler.c
index 7307ffe..3cb635b 100644
--- a/socket-handler.c
+++ b/socket-handler.c
@@ -169,9 +169,14 @@
 {
 	ssize_t rc;
 
-	rc = client_write_data(client, buf, len);
-	if (rc < 0)
-		return -1;
+	/* only write if the queue is empty */
+	if (!client->buf_len) {
+		rc = client_write_data(client, buf, len);
+		if (rc < 0)
+			return -1;
+	} else {
+		rc = 0;
+	}
 
 	if ((size_t)rc < len) {
 		rc = client_queue_data(client, buf + rc, len - rc);