8

the usual sample code for using HTTPClientSession goes something like this:

Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
std::ostream& ostr = session.sendRequest(req);

// Receive the response.
Poco::Net::HTTPResponse res;
std::istream& rs = session.receiveResponse(res);

the question is, how can I read from the rs input stream the entire data, while making sure that all of operations are non-blocking, so that I can cancel them at any time?

Aviad Rozenhek
  • 2,259
  • 3
  • 21
  • 42

1 Answers1

3

Just an idea, Try to put your code inside a thread.

http://pocoproject.org/slides/130-Threads.pdf

Regards

Cesar Ortiz
  • 884
  • 1
  • 8
  • 25
  • how would that help? I would just get this new thread blocked for an indefinite amount of time – Aviad Rozenhek Apr 30 '13 at 09:09
  • 1
    If you put your session.receiveResponse() inside a thread, you shouldn't worry about if it is blocking or not because you can run your main code in separated thread. If you want to cancel the blocking section, you could kill the thread or stop it in a ordered way. To exchange data between threads use references/pointers or queues synchronized with mutexes for example. If you want to block the receiveResponse() for a time you should look Time-Alives(setKeepAliveTimeout method) and timeouts. Good luck – Cesar Ortiz Apr 30 '13 at 10:34
  • Ok, then try with HTTPClientSession::setKeepAliveTimeout() method to configure a small TimeOut for your current connection. From documentation, "The stream is valid until sendRequest() is called or the session is destroyed", so if your rs stream doesn't receive nothing for a time period, it should continue without problems. – Cesar Ortiz Apr 30 '13 at 14:47
  • 3
    You can abort the blocking read on the HTTPClientSession by calling HTTPClientSession::abort() from another thread. – Günter Obiltschnig May 03 '13 at 08:43
  • @Günter: calling abort() from another thread is not a viable option on Android (it works well on OSX and iOS though...) – Ariel Malka Oct 22 '13 at 14:01