Re: Longpoll with Libsoup



On 05/13/2012 02:04 PM, Christian Hergert wrote:
> I have a similar question to Mark's post about longpolling a few weeks
> ago. I have a system that is doing lonpolling. However, I would like to
> stop various backend work when the client disconnects. I haven't found a
> way to get an event upon the client disconnecting.

Hm... yeah, when the client disconnects, the server side sees this as
the socket becoming readable, and then trying to read will return 0
bytes. But once it has received the complete request, SoupServer will
ignore the input side of the socket until it has finished sending the
response, so it's just not going to notice this.

>   Create a server, tried both sync and async w/ mainloop.

(SoupServer doesn't actually support sync; if you run soup_server_run(),
it just runs a GMainLoop internally.)

>   Attach to various signals on the message's SoupSocket such as:
>     - disconnect
>     - event
>   Get the raw FD for the socket w/ soup_socket_get_fd().
>   Create a new GSource that poll's for (G_IO_ERR | G_IO_HUP) on FD.

Right, these won't work because the socket doesn't actually get
disconnected, it just polls as readable.

Assuming you know your client isn't going to try to pipeline requests
(ie, sending a new request before the first one finishes), then you
could poll for G_IO_IN instead, and that will probably do what you want.
You could also call soup_socket_read() on it from the SoupServer
handler, which should fail with SOUP_SOCKET_WOULD_BLOCK, and then
connect to SoupSocket::readable.

-- Dan


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