!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;
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] "
"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 */
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:
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++)
continue;
wsi[client]->protocol->callback(wsi[client], LWS_CALLBACK_SEND,
- &wsi[client]->user_space, NULL, 0);
+ wsi[client]->user_space, NULL, 0);
}
continue;
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;
</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>