Detect disconnect durring chunked response

Please post support and help requests here.
zarnce
Posts: 12
Joined: 08 Jan 2013, 22:56

Detect disconnect durring chunked response

Postby zarnce » 16 Jan 2013, 00:50

Is there any way to determine if the connection was lost durring a long running chunked http session?

Thanks
Brian

bakercp
Posts: 4
Joined: 17 Jan 2013, 20:57

Re: Detect disconnect durring chunked response

Postby bakercp » 17 Jan 2013, 21:05

Hey, I am dealing with a similar issue -- the way I detect a disconnect (say a tab being closed, etc) is to do the following in my HTTPRequestHandler::handleRequest method:

Code: Select all

        std::ostream& ostr = response.send(); // get output stream

        while(ostr.good()) {
             ostr << "hello"; // write to the output stream
        }

// ostr.good() is != true as soon as the client disconnects.


My problem comes when the server thread is being cleaned up. I am using 1.4.3 on OSX and my program dies with a SIGPIPE error after the HTTPRequestHandler has been destroyed. Not sure why and perhaps it is fixed in a newer version of Poco.

zarnce
Posts: 12
Joined: 08 Jan 2013, 22:56

Re: Detect disconnect durring chunked response

Postby zarnce » 17 Jan 2013, 23:40

That looks like a good solution. I found a different way but it involves adding connected method to HTTPServerResponse. I was just about to request a pull when I saw your post. I saw that HTTPServerResponseImpl holds the Session. When a read or write fails an exception is held. So I was going to make a check for that.

bool HTTPServerResponseImpl::connected() const
{
return _session.networkException() == nullptr;
}

I tested with 1.4.6 and 1.5.1 and did not see the SIGPIPE.

Brian

clay
Posts: 3
Joined: 18 Jan 2013, 01:00

Re: Detect disconnect durring chunked response

Postby clay » 18 Jan 2013, 20:25

bakercp wrote:My problem comes when the server thread is being cleaned up. I am using 1.4.3 on OSX and my program dies with a SIGPIPE error after the HTTPRequestHandler has been destroyed. Not sure why and perhaps it is fixed in a newer version of Poco.


I'm running on WinCE, and I see an exception get raised and printed to the console when the RequestHandler gets destroyed, however my process does not die. Perhaps this is the same problem?


Return to “Support”

Who is online

Users browsing this forum: No registered users and 2 guests