[Libwebsockets] polling for file descriptor i/o
per at bothner.com
Sun Feb 26 21:17:38 CET 2017
On 02/26/2017 11:37 AM, Andy Green wrote:
> How about you also explain what kind of semantics you are looking for from lws around that fd to save us having another round of "that's not what I need"?
Sure. The ldomterm program starts up a child process, with a pty.
When the child process writes to its pty,
input becomes available on the master fd in the ldomterm process.
We need to take this inpur and send it (using lws_write)
to the browser at the other end of the websocket, so that
the browser can display the output.
The current implementation:
starts up a separate thread (function thread_run_command) to listen
to the master fd (using a select near line 185), put it on a queue,
and later the main thread sends it to the server (see case
LWS_CALLBACK_SERVER_WRITEABLE near line 322).
This seems very complicated and inefficient. We should not be using
a separate event loop using a duplicate select. Instead, what I'd like is
a way to add the master pty file descriptor (client->pty) to the main
select/poll used by lws's event loop.
A really simple API would be:
lws_add_input_hook (lws, client->pty, callback_function);
The signature of the callback function could match the other callback
functions. It might also make sense for these input-available events
to be handled as a different protocol with an entry in the
struct lws_protocols protocols table. I don't know enough about lws internals
and design to determine what is the best approach.
per at bothner.com http://per.bothner.com/
More information about the Libwebsockets