Closed jvo203 closed 7 months ago
Closing this issue as I have implemented a low-level fix: creating text/binary/pong WebSocket messages directly in my application code. This completely avoids having to call libmicrohttpd MHD_websocket_encode_*
functions. All libmicrohttpd does is simply to upgrade the HTTP connection to WebSocket and decode the incoming WebSocket stream. All the responses are handled at a lower level, which results in improved performance (avoids the extra memory allocation step inside the encode_*
functions).
It's more of a question than an issue and I realise the WebSocket functionality is still experimental. Whilst adapting your WebSocket Chat Server example so suit my project there has been this nagging issue: do all the WebSocket stream encode/decode functions like
MHD_websocket_encode_pong(ws, ...)
,MHD_websocket_encode_text(ws, ...)
andMHD_websocket_encode_binary(ws, ...)
need a mutex protection in a fully multi-threaded environment?Given a single unique WebSocket stream
session->ws
and a number of producer POSIX threads creating WebSocket messages on the server, does one need to do thisprior to calling
send_all()
or is theencode_mtx
completely unnecessary? Each producer thread operates on its ownframe_data, frame_len
variables. In addition, thesend_all()
internally locks a separatesend_mtx
to protect the TCP WebSocket writes:I realise there is also another - albeit much more low-level - example that can be followed:
websocket_threaded_example.c
. It does not rely on a unique WebSocket streamsession->ws
.libmicrohttpd_ws
is still experimental but it's great! It certainly beats the mongoose networking library, as per the attached PDF slide (ignore the 1st page, written in Japanese). libmicrohttpd.pdf