Move context creation outside of the server block
Add a GCD time dispatch source

Use a timer dispatch source to poll regularly the websocket instead of an infinite while loop. First step to move away from polling and instead use other kind of dispatch sources (file descriptors for instance).
Use a serial queue for messaging

The polling for synchronous messaging and the push operations, are now scheduled in a serial queue. A serial queue give us a lock free code but potentially less performances, however as libwebsockets doesn't give us concurrent I/O the performance penalty will only be visible when a lot of processing is done in the handleRequestBlock.
Move the libwebsocket_callback_on_writable function out of the polling loop

The libwebsocket_callback_on_writable indicates that we want to be called back when the socket is writable. The next time libwebsocket_service is called, if the socket is writable, our callback function will be called.