fix-user-pointer-bug.patch
Signed-off-by: Andy Green <andy@warmcat.com>
diff --git a/lib/handshake.c b/lib/handshake.c
index 7deb581..95297a0 100644
--- a/lib/handshake.c
+++ b/lib/handshake.c
@@ -96,7 +96,7 @@
!wsi->utf8_token[WSI_TOKEN_CONNECTION].token_len) {
if (wsi->protocol->callback)
(wsi->protocol->callback)(wsi, LWS_CALLBACK_HTTP,
- &wsi->user_space,
+ wsi->user_space,
wsi->utf8_token[WSI_TOKEN_GET_URI].token, 0);
wsi->state = WSI_STATE_HTTP;
return 0;
@@ -145,6 +145,9 @@
wsi->protocol++;
}
+
+ /* we didn't find a protocol he wanted? */
+
if (wsi->protocol->callback == NULL) {
if (wsi->utf8_token[WSI_TOKEN_PROTOCOL].token == NULL)
fprintf(stderr, "[no protocol] "
@@ -166,7 +169,9 @@
"conn user space\n");
goto bail;
}
- }
+ fprintf(stderr, "user allocated %d at %p for wsi %p\n", wsi->protocol->per_session_data_size, wsi->user_space, wsi);
+ } else
+ wsi->user_space = NULL;
/* create the response packet */
@@ -275,7 +280,7 @@
if (wsi->protocol->callback)
wsi->protocol->callback(wsi, LWS_CALLBACK_ESTABLISHED,
- &wsi->user_space, NULL, 0);
+ wsi->user_space, NULL, 0);
break;
case WSI_STATE_ESTABLISHED:
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index 79d2e22..c680e52 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -82,7 +82,7 @@
wsi->state = WSI_STATE_DEAD_SOCKET;
if (wsi->protocol->callback && n == WSI_STATE_ESTABLISHED)
- wsi->protocol->callback(wsi, LWS_CALLBACK_CLOSED, &wsi->user_space,
+ wsi->protocol->callback(wsi, LWS_CALLBACK_CLOSED, wsi->user_space,
NULL, 0);
for (n = 0; n < WSI_TOKEN_COUNT; n++)
@@ -444,7 +444,7 @@
continue;
wsi[client]->protocol->callback(wsi[client], LWS_CALLBACK_SEND,
- &wsi[client]->user_space, NULL, 0);
+ wsi[client]->user_space, NULL, 0);
}
continue;
diff --git a/lib/parsers.c b/lib/parsers.c
index 52cd126..5a98f6f 100644
--- a/lib/parsers.c
+++ b/lib/parsers.c
@@ -212,7 +212,7 @@
issue:
if (wsi->protocol->callback)
wsi->protocol->callback(wsi, LWS_CALLBACK_RECEIVE,
- &wsi->user_space,
+ wsi->user_space,
&wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
wsi->rx_user_buffer_head);
wsi->rx_user_buffer_head = 0;
diff --git a/libwebsockets-api-doc.html b/libwebsockets-api-doc.html
index e7dcb82..b418db6 100644
--- a/libwebsockets-api-doc.html
+++ b/libwebsockets-api-doc.html
@@ -93,14 +93,23 @@
</dl>
<h3>Description</h3>
<blockquote>
-This function forks to create the listening socket and takes care
+This function creates the listening socket and takes care
of all initialization in one step.
<p>
-The callback function is called for a handful of events including
-http requests coming in, websocket connections becoming
+It does not return since it sits in a service loop and operates via the
+callbacks given in <tt><b>protocol</b></tt>. User code should fork before calling
+<b>libwebsocket_create_server</b> if it wants to do other things in
+parallel other than serve websockets.
+<p>
+The protocol callback functions are called for a handful of events
+including http requests coming in, websocket connections becoming
established, and data arriving; it's also called periodically to allow
async transmission.
<p>
+HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
+at that time websocket protocol has not been negotiated. Other
+protocols after the first one never see any HTTP callack activity.
+<p>
The server created is a simple http server by default; part of the
websocket standard is upgrading this http connection to a websocket one.
<p>