add explicit error for partial send

This patch adds code to handle the situation that a prepared user buffer could not all be sent on the
socket at once.  There are two kinds of situation to handle

1) User code handles it: The connection only has extensions active that do not rewrite the buffer.
In this case, the patch caused libwebsocket_write() to simply return the amount of user buffer that
was consumed (this is specifically the amount of user buffer used in sending what was accepted,
nothing else).  So user code can just advance its buffer that much and resume sending when the socket
is writable again.  This continues the frame rather than starting a new one or new fragment.

2) The connections has extensions active which actually send something quite different than what the
user buffer contains, for example a compression extension.  In this case, libwebsockets will dynamically
malloc a buffer to contain a copy of the remaining unsent data, request notifiction when writeable again,
and automatically spill and free this buffer with the highest priority before passing on the writable
notification to anything else.  For this situation, the call to write will return that it used the
whole user buffer, even though part is still rebuffered.

This patch should enable libwebsockets to detect the two cases and take the appropriate action.

There are also two choices for user code to deal with partial sends.

1) Leave the no_buffer_all_partial_tx member in the protocol struct at zero.  The library will dyamically
buffer anything you send that did not get completely written to the socket, and automatically spill it next
time the socket is writable.  You can use this method if your sent frames are relatvely small and unlikely to get
truncated anyway.

2) Set the no_buffer_all_partial_tx member in the protocol struct.  User code now needs to take care of the
return value from libwebsocket_write() and deal with resending the remainder if not all of the requested amount
got sent.  You should use this method if you are sending large messages and want to maximize throughput and efficiency.

Since the new member no_buffer_all_partial_tx will be zero by default, this patch will auto-rebuffer any
partial sends by default.  That's good for most cases but if you attempt to send large blocks, make sure you
follow option 2) above.

Signed-off-by: Andy Green <andy.green@linaro.org>
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index ea8a8ff..7e7a7b2 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -370,6 +370,11 @@
 			free(wsi->u.ws.rxflow_buffer);
 			wsi->u.ws.rxflow_buffer = NULL;
 		}
+		if (wsi->u.ws.truncated_send_malloc) {
+			/* not going to be completed... nuke it */
+			free(wsi->u.ws.truncated_send_malloc);
+			wsi->u.ws.truncated_send_malloc = NULL;
+		}
 	}
 
 	/* tell the user it's all over for this guy */
@@ -658,6 +663,16 @@
 	int m;
 	int handled = 0;
 
+	/* pending truncated sends have uber priority */
+
+	if (wsi->u.ws.truncated_send_malloc) {
+		lws_issue_raw(wsi, wsi->u.ws.truncated_send_malloc +
+				wsi->u.ws.truncated_send_offset,
+						wsi->u.ws.truncated_send_len);
+		/* leave POLLOUT active either way */
+		return 0;
+	}
+
 	for (n = 0; n < wsi->count_active_extensions; n++) {
 		if (!wsi->active_extensions[n]->callback)
 			continue;