From 0c9563bbd255f4d98bd463f71f967f8bf4be7040 Mon Sep 17 00:00:00 2001
From: Andy Green <andy.green@linaro.org>
Date: Mon, 10 Jun 2013 22:54:40 +0800
Subject: [PATCH] add LWS_CALLBACK_CLOSED_HTTP

Adds a callback to allow handling HTTP protocol connections
closing.

Signed-off-by: Andy Green <andy.green@linaro.org>
---
 changelog           | 3 +++
 lib/libwebsockets.c | 2 ++
 lib/libwebsockets.h | 3 +++
 3 files changed, 8 insertions(+)

diff --git a/changelog b/changelog
index 8b79f121..f6b85d94 100644
--- a/changelog
+++ b/changelog
@@ -28,6 +28,9 @@ User api additions
 	then does not have to try to track while connections it choked, this
 	will free up all of them in one call.
 
+ - there's a new, optional callback LWS_CALLBACK_CLOSED_HTTP which gets
+	called when an HTTP protocol socket closes
+
 
 User api changes
 ----------------
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index d312390d..e75a5100 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -210,6 +210,8 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
 		lwsl_debug("closing http fd %d\n", wsi->u.http.fd);
 		close(wsi->u.http.fd);
 		wsi->u.http.fd = 0;
+		context->protocols[0].callback(context, wsi,
+			LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0);
 	}
 
 #ifndef LWS_NO_EXTENSIONS
diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h
index 65bae145..9f686bd8 100644
--- a/lib/libwebsockets.h
+++ b/lib/libwebsockets.h
@@ -138,6 +138,7 @@ enum libwebsocket_callback_reasons {
 	LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH,
 	LWS_CALLBACK_CLIENT_ESTABLISHED,
 	LWS_CALLBACK_CLOSED,
+	LWS_CALLBACK_CLOSED_HTTP,
 	LWS_CALLBACK_RECEIVE,
 	LWS_CALLBACK_CLIENT_RECEIVE,
 	LWS_CALLBACK_CLIENT_RECEIVE_PONG,
@@ -419,6 +420,8 @@ struct libwebsocket_extension;
  *
  *	LWS_CALLBACK_CLOSED: when the websocket session ends
  *
+ *	LWS_CALLBACK_CLOSED_HTTP: when a HTTP (non-websocket) session ends
+ *
  *	LWS_CALLBACK_RECEIVE: data has appeared for this server endpoint from a
  *				remote client, it can be found at *in and is
  *				len bytes long
-- 
GitLab