Re: How to make libsoup read from an already-open stream?



On 05/30/2012 02:49 PM, Trev wrote:
> On 5/30/2012, Dan Winship wrote:
>>> What exactly are you doing? There might be some other way to go about it
>>> that would work...
>>>
>>> -- Dan
> 
> Processing a WebSocket response that doesn't include a protocol switch.

Hm... you can parse the headers easily enough
(soup_headers_parse_response()), but if the response uses chunked
encoding, there's no exposed API that would let you "flatten" that.

One possibility (which turns out to be ugly) would be to send the
request via libsoup instead, and connect to request-started on the
SoupSession (to get a copy of the SoupSocket) and got-informational on
the SoupMessage (to get notified of a 101 response). If
got-informational is emitted, call soup_session_pause_message() to stop
libsoup from doing any further processing, then call
soup_socket_get_fd() to get the socket file descriptor, and create a
GSocket from that and a GSocketConnection from the GSocket.

The really ugly part is that you'd need to leave the SoupMessage and
SoupSession around until you're done with the websocket though, because
otherwise libsoup would close the connection.

Adding an API to cleanly steal the GSocketConnection away from a message
seems like it might be a good idea. (That would also make it possible to
implement the server side of CONNECT, which is currently impossible.)

-- Dan


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