[Libwebsockets] Lws_service with specific socket

Edwin van den Oetelaar oetelaar.automatisering at gmail.com
Tue Dec 19 14:21:06 CET 2017


On Tue, Dec 19, 2017 at 2:08 PM, Théo BRIGNOL <theo.brignol at imerir.com>
wrote:

> Ok sorry for my unclear explanation.
>
> Simply :
>
> I have a file descriptor of a socket which is open. I'd like to know if
> it's possible to construct a context using this socket. And to start a
> lws_service on it.
>
>
If the socket is just a clean socket, no data has flowed through it (like a
socket you get from accept() ) then you might be able to do it.
(I have no example, but technically it should be possible to start data
flow and handshaking on it)

If the socket has been used for http/ws-protocol, like you suggested
(because you want to start different sub-programs based on something that
came through the socket) I think you will not succeed.

Why not use the library as it was designed?
Use a more distributed design, let the WS server take the network-calls and
go from there.
Take a look at loosly coupled services and more scalable designs. Look at
ZeroMQ book for inspiration.

good luck,
Edwin


>
> Thanks,
> Theo
>
>
> 2017-12-19 12:04 GMT+01:00 Edwin van den Oetelaar <
> oetelaar.automatisering at gmail.com>:
>
>>
>>
>> On Tue, Dec 19, 2017 at 11:42 AM, Théo BRIGNOL <theo.brignol at imerir.com>
>> wrote:
>>
>>>
>>> Hello,
>>>
>>> I have a question regarding a simple case.
>>>
>>> I want to create a main socket in my main program.
>>> In order to do that, I create a main context with default protocols and
>>> one specific listening port.
>>>
>>
>> This I understand.
>>
>>
>>>
>>> This main program will launch as many as sub-programs that whe decided
>>> with the function "execl".
>>>
>>
>> This makes no sense to me, you want to replace the current process with
>> another?
>> You destroy all state in the orignal connection (WS state, it not just a
>> file descriptor)
>>
>> ref : https://linux.die.net/man/3/execl
>>
>> The *exec*() family of functions replaces the current process image with
>> a new process image.
>>
>>
>>>
>>> I want this sub-programs to redefine protocols, and accept connection on
>>> the main port on the main socket (the "father" socket). Note that with
>>> execl I can't pass main context as a parameter.
>>>
>>> The fact is that I tried many solutions without succes
>>> (LWS_EXPLICIT_VHOST option, external poll fd, etc..).
>>>
>>> Have you any idea in order to do that ?
>>>
>>
>> I have not a clue what you try to achieve here. Or why?
>> Do you have any example where this approach is a good solution to a
>> problem?
>> I do not know everything, so I am willing to learn here.
>>
>>
>>>
>>> Thank you for your comprehension.
>>>
>>
>> ;-) I am completely without comprehension ;-)
>>
>> Greetings,
>> Edwin
>>
>>
>>> Best Regards,
>>>
>>> Theo
>>>
>>> _______________________________________________
>>> Libwebsockets mailing list
>>> Libwebsockets at ml.libwebsockets.org
>>> https://libwebsockets.org/mailman/listinfo/libwebsockets
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20171219/644b6be7/attachment-0002.html>


More information about the Libwebsockets mailing list