[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] integration with my websockets
From: |
Christian Grothoff |
Subject: |
Re: [libmicrohttpd] integration with my websockets |
Date: |
Tue, 11 Apr 2017 20:45:47 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 |
Jose,
Have you considered doing
if upgrade-requested-for(req) then
my_cls = create-websocket-for(req)
if my_cls created then
MHD_create_response_for_upgrade (&my_handler, my_cls);
else
reply "internal error"
end
else
....
end
Basically, use the "upgrade_handler_cls" argument to pass along any kind
of state you need for your upgrade handling. That way, you
can do pretty much any initialization/setup work you require before you
queue the response object and thus lock yourself into some particular
type of response.
As far as I see it, the only limitation here is that you cannot touch
the socket itself. (However, technically you can touch it as well using
MHD_CONNECTION_INFO_CONNECTION_FD for HTTP-only connections, but it's
usually not a good idea to hack around with that.)
Happy hacking!
-Christian
On 04/11/2017 07:23 PM, José Bollo wrote:
>> Could you explain a bit more do you want to implement and why it is
>> not possible?
>
> This pseudo-code is no more possible:
>
> if upgrade-requested-for(req) then
> handler = create-websocket-for(req)
> if handler created then
> reply "switch protocol"
> else
> reply "internal error"
> end
> else
> ....
> end
>
> Instead you may write:
>
> if upgrade-requested-for(req) then
> reply "switch protocol" with callback
> else
> ....
> end
>
> and in the callback
>
> handler = create-websocket-for(req)
> if handler created then
> cool
> else
> not cool, too late for sending an internal error
> end
>
> But as written there is something not cool cool
> So the following version is dandling with the hole
>
> if upgrade-requested-for(req) then
> handler = create-websocket-lazy
> if handler created then
> reply "switch protocol" with callback
> else
> reply "internal error"
> end
> else
> ....
> end
>
> and in the callback
>
> attach-websocket-socket(...)
>
>>
>>>> Third, do you plan to provide a new version soon?
>>
>> Yes, watch this list. :)
>>
>
>
signature.asc
Description: OpenPGP digital signature