[Libwebsockets] Synchronous API wrapping libwebsockets?
Duy Lan Nguyen
ndlan2k at gmail.com
Sun Nov 9 02:17:12 CET 2014
Appreciate if you could help. I'm trying to implement a simple Synchronous
API wrapping libwebsockets (for client side, not server side), roughly as
MYSOCK = Connect(...);
STATUS Send(MYSOCK, char* pbData, uint cbData, uint dwFlags);
STATUS Receive(MYSOCK, char* pbData, uint cbData, uint dwFlags);
DO YOU HAVE any ADVICE on HOW to do that most efficiently?
I actually have the following design
A global queue of RecvRequest struct
A global queue of SendRequest struct
Create a separate thread
- calling libwebsocket_create_context()
- calling libwebsocket_client_connect()
- running the loop libwebsocket_service()
Just shutdown the above thread and callings properly
Add its SendRequest struct to the queue
Wait for its event SendRequest.CompleteEvent
Add its RecvRequest struct to the queue
Wait for its event RecvRequest.CompleteEvent
- Throw the previous SendRequest.CompleteEvent, if there is any.
- Call libwebsocket_write() to send current SendRequest.Data in the queue,
if there is any.
- Remove the current SendRequest in the queue to be the "previous" one.
- Call libwebsocket_callback_on_writable()
- Pass received data to RecvRequest.Data in the queue, if there is any.
- Remove the current RecvRequest in the queue.
- Throw the its RecvRequest.CompleteEvent.
DO YOU have any COMMENT on this design?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libwebsockets