From 54cb34632024a0f7ce47ec16655661d892d7634f Mon Sep 17 00:00:00 2001
From: Andy Green <andy.green@linaro.org>
Date: Thu, 14 Feb 2013 22:23:54 +0800
Subject: [PATCH] introduce LWS_CALLBACK_HTTP_WRITEABLE

Signed-off-by: Andy Green <andy.green@linaro.org>
---
 changelog           | 10 ++++++++++
 lib/libwebsockets.h |  4 ++++
 lib/server.c        | 13 ++++++++++++-
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/changelog b/changelog
index fc866dee..ea3cdf0d 100644
--- a/changelog
+++ b/changelog
@@ -1,6 +1,16 @@
 Changelog
 ---------
 
+(development since 1.22)
+
+User api additions
+------------------
+
+ - You can now call libwebsocket_callback_on_writable() on http connectons,
+ 	and get a LWS_CALLBACK_HTTP_WRITEABLE callback, the same way you can
+	regulate writes with a websocket protocol connection.
+
+
 v1.21-chrome26-firefox18
 ========================
 
diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h
index d038a44a..3b1e8373 100644
--- a/lib/libwebsockets.h
+++ b/lib/libwebsockets.h
@@ -134,6 +134,7 @@ enum libwebsocket_callback_reasons {
 	LWS_CALLBACK_SERVER_WRITEABLE,
 	LWS_CALLBACK_HTTP,
 	LWS_CALLBACK_HTTP_FILE_COMPLETION,
+	LWS_CALLBACK_HTTP_WRITEABLE,
 	LWS_CALLBACK_FILTER_NETWORK_CONNECTION,
 	LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION,
 	LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS,
@@ -436,6 +437,9 @@ struct libwebsocket_extension;
  *				total number of client connections allowed set
  *				by MAX_CLIENTS.
  *
+ *	LWS_CALLBACK_HTTP_WRITEABLE: you can write more down the http protocol
+ *		link now.
+ *
  *	LWS_CALLBACK_HTTP_FILE_COMPLETION: a file requested to be send down
  *				http link has completed.
  *
diff --git a/lib/server.c b/lib/server.c
index 3e81290f..72d9e084 100644
--- a/lib/server.c
+++ b/lib/server.c
@@ -192,8 +192,19 @@ int lws_server_socket_service(struct libwebsocket_context *context,
 		/* one shot */
 		pollfd->events &= ~POLLOUT;
 
-		if (wsi->state != WSI_STATE_HTTP_ISSUING_FILE)
+		if (wsi->state != WSI_STATE_HTTP_ISSUING_FILE) {
+			n = user_callback_handle_rxflow(
+					wsi->protocol->callback,
+					wsi->protocol->owning_server,
+					wsi, LWS_CALLBACK_HTTP_WRITEABLE,
+					wsi->user_space,
+					NULL,
+					0);
+			if (n < 0)
+				libwebsocket_close_and_free_session(
+				       context, wsi, LWS_CLOSE_STATUS_NOSTATUS);
 			break;
+		}
 
 		/* nonzero for completion or error */
 		if (libwebsockets_serve_http_file_fragment(context, wsi))
-- 
GitLab