diff --git a/changelog b/changelog
index 95e6194060e7f04773601c556b3ed262730e3b11..f50d87bc6cf4451313654b53280aa8238e7153ec 100644
--- a/changelog
+++ b/changelog
@@ -21,6 +21,12 @@ over ssl or not.  If LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT is used, both
 ssl and non-ssl connections are possible and may need to be treated differently
 in the user code.
 
+int lws_partial_buffered(wsi) added... should be checked after any
+libwebsocket_write that will be followed by another libwebsocket_write inside
+the same writeable callback.  If set, you can't do any more writes until the
+writeable callback is called again.  If you only do one write per writeable callback,
+you can ignore this.
+
 
 User api removal
 ----------------
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index a5ec698b45f5cd42d66ba9e87bbd79406bc66f95..166dd3c5e741ae495878f2cf5725426b7142af13 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -769,3 +769,26 @@ lws_is_ssl(struct libwebsocket *wsi)
 {
 	return wsi->use_ssl;
 }
+
+/**
+ * lws_partial_buffered() - find out if lws buffered the last write
+ * @wsi:	websocket connection to check
+ *
+ * Returns 1 if you cannot use libwebsocket_write because the last
+ * write on this connection is still buffered, and can't be cleared without
+ * returning to the service loop and waiting for the connection to be
+ * writeable again.
+ * 
+ * If you will try to do >1 libwebsocket_write call inside a single
+ * WRITEABLE callback, you must check this after every write and bail if
+ * set, ask for a new writeable callback and continue writing from there.
+ * 
+ * This is never set at the start of a writeable callback, but any write
+ * may set it.
+ */
+
+LWS_VISIBLE int
+lws_partial_buffered(struct libwebsocket *wsi)
+{
+	return !!wsi->truncated_send_len;	
+}
diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h
index a0c500acc1532620d7080fc09131ee184408c53c..7b5e697979f557956e591b8ca61f120fce446a0e 100644
--- a/lib/libwebsockets.h
+++ b/lib/libwebsockets.h
@@ -1169,6 +1169,9 @@ lws_daemonize(const char *_lock_path);
 LWS_VISIBLE LWS_EXTERN int
 lws_send_pipe_choked(struct libwebsocket *wsi);
 
+LWS_VISIBLE LWS_EXTERN int
+lws_partial_buffered(struct libwebsocket *wsi);
+
 LWS_VISIBLE LWS_EXTERN int
 lws_frame_is_binary(struct libwebsocket *wsi);
 
diff --git a/test-server/test-server.c b/test-server/test-server.c
index 682bb5d32f824e801aae7cb323fdcfca90d2a70d..c43b9c4553b15d1558ba901b4585eba56e1837e9 100644
--- a/test-server/test-server.c
+++ b/test-server/test-server.c
@@ -386,13 +386,17 @@ static int callback_http(struct libwebsocket_context *context,
 			if (m) /* while still active, extend timeout */
 				libwebsocket_set_timeout(wsi,
 					PENDING_TIMEOUT_HTTP_CONTENT, 5);
+			
+			/* if he has indigestion, let him clear it before eating more */
+			if (lws_partial_buffered(wsi))
+				break;
 
 		} while (!lws_send_pipe_choked(wsi));
 		libwebsocket_callback_on_writable(context, wsi);
 		break;
 flush_bail:
 		/* true if still partial pending */
-		if (lws_send_pipe_choked(wsi)) {
+		if (lws_partial_buffered(wsi)) {
 			libwebsocket_callback_on_writable(context, wsi);
 			break;
 		}
@@ -632,7 +636,7 @@ callback_lws_mirror(struct libwebsocket_context *context,
 
 			// lwsl_debug("tx fifo %d\n", (ringbuffer_head - pss->ringbuffer_tail) & (MAX_MESSAGE_QUEUE - 1));
 
-			if (lws_send_pipe_choked(wsi)) {
+			if (lws_partial_buffered(wsi) || lws_send_pipe_choked(wsi)) {
 				libwebsocket_callback_on_writable(context, wsi);
 				break;
 			}