From 099f789d2ff2f09ad6d890ca08f4b645db8cc0d8 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 15 Feb 2013 10:25:58 +0800 Subject: [PATCH] README.coding add note about closing connections Signed-off-by: Andy Green --- README.coding | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.coding b/README.coding index 4f4c27a5..bb093fb8 100644 --- a/README.coding +++ b/README.coding @@ -67,6 +67,27 @@ in the ...WRITEABLE callback. See the test server code for an example of how to do this. +Closing connections from the user side +-------------------------------------- + +When you want to close a connection, you do it by returning -1 from a +callback for that connection. + +You can provoke a callback by calling libwebsocket_callback_on_writable on +the wsi, then notice in the callback you want to close it and just return -1. +But usually, the decision to close is made in a callback already and returning +-1 is simple. + +If the socket knows the connection is dead, because the peer closed or there +was an affirmitive network error like a FIN coming, then libwebsockets will +take care of closing the connection automatically. + +If you have a silently dead connection, it's possible to enter a state where +the send pipe on the connection is choked but no ack will ever come, so the +dead connection will never become writeable. To cover that, you can use TCP +keepalives (see later in this document) + + Fragmented messages -------------------