summaryrefslogtreecommitdiff
path: root/lib/libwebsockets.h
diff options
context:
space:
mode:
authorAndy Green <andy.green@linaro.org>2015-12-26 17:20:34 +0800
committerAndy Green <andy.green@linaro.org>2015-12-26 17:20:34 +0800
commit1fb95e8084bc7b27e72bf199ba422efdfbee360b (patch)
treee2405ad4e0641181056ef2e8dd250b9b8f061c4d /lib/libwebsockets.h
parent066a7a1801102e8dbebc3cf51bba82a83bf15e88 (diff)
downloadlibwebsockets-1fb95e8084bc7b27e72bf199ba422efdfbee360b.tar.gz
libwebsockets-1fb95e8084bc7b27e72bf199ba422efdfbee360b.tar.bz2
libwebsockets-1fb95e8084bc7b27e72bf199ba422efdfbee360b.zip
close add api to control sent close frame contents
This adds an api lws_close_reason() which lets you control what will be sent in the close frame when the connection is closed by returning nonzero from the user callback. The test server demo is extended to prove it works in both directions. With this, we should have nice close support. https://github.com/warmcat/libwebsockets/issues/196 Signed-off-by: Andy Green <andy.green@linaro.org>
Diffstat (limited to 'lib/libwebsockets.h')
-rw-r--r--lib/libwebsockets.h26
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h
index 26587b66..830fc407 100644
--- a/lib/libwebsockets.h
+++ b/lib/libwebsockets.h
@@ -453,7 +453,7 @@ enum lws_write_protocol {
/* special 04+ opcodes */
- LWS_WRITE_CLOSE = 4,
+ /* LWS_WRITE_CLOSE is handled by lws_close_reason() */
LWS_WRITE_PING = 5,
LWS_WRITE_PONG = 6,
@@ -1409,7 +1409,6 @@ lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
* LWS_WRITE_TEXT,
* LWS_WRITE_BINARY,
* LWS_WRITE_CONTINUATION,
- * LWS_WRITE_CLOSE,
* LWS_WRITE_PING,
* LWS_WRITE_PONG
*
@@ -1428,13 +1427,6 @@ lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
* memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, 128);
*
* lws_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128, LWS_WRITE_TEXT);
- *
- * When sending
- *
- * LWS_WRITE_CLOSE
- *
- * only, you must allow your buffer to be 2 bytes longer than otherwise
- * needed.
*
* When sending HTTP, with
*
@@ -1476,6 +1468,22 @@ LWS_VISIBLE LWS_EXTERN int
lws_write(struct lws *wsi, unsigned char *buf, size_t len,
enum lws_write_protocol protocol);
+/**
+ * lws_close_reason - Set reason and aux data to send with Close packet
+ * If you are going to return nonzero from the callback
+ * requesting the connection to close, you can optionally
+ * call this to set the reason the peer will be told if
+ * possible.
+ *
+ * @wsi: The websocket connection to set the close reason on
+ * @status: A valid close status from websocket standard
+ * @buf: NULL or buffer containing up to 124 bytes of auxiliary data
+ * @len: Length of data in @buf to send
+ */
+LWS_VISIBLE LWS_EXTERN void
+lws_close_reason(struct lws *wsi, enum lws_close_status status,
+ unsigned char *buf, size_t len);
+
/* helper for case where buffer may be const */
#define lws_write_http(wsi, buf, len) \
lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP)