libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] integration with my websockets


From: José Bollo
Subject: Re: [libmicrohttpd] integration with my websockets
Date: Wed, 12 Apr 2017 10:21:35 +0200

On Tue, 11 Apr 2017 20:45:47 +0200
Christian Grothoff <address@hidden> wrote:

> 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.)

That is exactly what I put in the third pseudo code example but I
forgive you to not being able to discover it by yourself.

So yes it can be done that way. But now I have to handle 2 function:
one for the creation and one for attaching the socket (or the stuff).
Because there is a negociation of protocol and thus I use tables, I
have to update tables and redesign things.

But I'm happy to get a solution from MHD instead of having a patch.


Best Regards
josé

> 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. :)
> >>  
> > 
> >   
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]