HTTPClientSession.receiveResponse empty istream with c++11

Please post support and help requests here.
Posts: 3
Joined: 18 Jul 2013, 18:08

HTTPClientSession.receiveResponse empty istream with c++11

Postby timstirling » 18 Jul 2013, 18:31

I am having a problem with HTTPClientSession.receiveResponse since switching to gcc 4.8 using c++11 flags (on maxOsX lion).
I have some simple code that is supposed to connect to a basic http server which responds with a JSON string. This worked find with earlier versions of gcc but I had to change to use c++11 for the project. Everything in the tens of thousands of liens of code work as before except the receiveResponse does not return an input stream with data.
The status is 200 OK but the Istrream is just blank. This seems to cause the StreamCopier::copyToString to fail with with malloc/pointer errors ( see bottom of post).

The code is very standard, here it is cleaned up and the URL changed to

Code: Select all

      URI m_uri("");
      HTTPClientSession m_session(m_uri.getHost(),m_uri.getPort());
      string path(m_uri.getPathAndQuery());

      // send request
      HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);

      // get response
      HTTPResponse res;

      istream &is = m_session.receiveResponse(res);
      // here is normally some error checking but for this post I just cout the status and get 200 OK
      cout <<  res.getStatus() << "  " << res.getReason()  << endl;
     // Copy response
      string results;
     // StreamCopier::copyToString(is, results);   // Fails with c++11 (malloc/pointer error)
      is >> results;                                               // Works for results string is empty.
      cout << results <<endl;                                // blank

Stream Copier Error:

Code: Select all

atlasTest(31646) malloc: *** error for object 0x1006c2840: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

Program received signal SIGABRT, Aborted.
0x00007fff8855982a in __kill ()
(gdb) where
#0  0x00007fff8855982a in __kill ()
#1  0x00007fff8798ba9c in abort ()
#2  0x00007fff879ea84c in free ()
#3  0x00007fff8ef71702 in std::string::_Rep::_M_dispose ()
#4  0x00007fff8ef72424 in std::string::reserve ()
#5  0x00007fff8ef7262b in std::string::append ()
#6  0x000000010081f17f in Poco::StreamCopier::copyToString ()
..... // function that does the http request as above

tested a few different URI and the same issue, I get a status 200 OK but no actual response. Everything was fine pre c++11 installation but I cannot go back to that now.
I downloaded the latest Poco Source from here and compiled/installed but that made no difference.
I spent a couple of hours searching google and trying a few things but to no avail so now I am lost. If I can't get this working we will have to drop Poco and look elsewhere, which is a shame because I really liked the clean API and simplicity!

Any idea what is going on? Any help much appreciated!

Posts: 1375
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: HTTPClientSession.receiveResponse empty istream with c++

Postby alex » 19 Jul 2013, 16:48

There were other problems reported with c++11. It is not clear whether the problem is on POCO side or the compiler/standard library. We will, of course, eventually address this but a fast fix that you require would only be feasible through a commercial contract. If you are interested in that, you can contact either Applied Informatics or me directly. Alternatively, if you find the root cause of your particular problem and fix it yourself, we'll gladly accept the contribution.

Posts: 3
Joined: 18 Jul 2013, 18:08

Re: HTTPClientSession.receiveResponse empty istream with c++

Postby timstirling » 19 Jul 2013, 17:21

Thank you for your reply. Sadly I don't think a commercial contract is likely because we only use this small part of Poco so other free libraries will likely be used instead.

One interesting thing is I used getContentLength() on the reponse and the length was exactly the right size, e.g. server sent 470 bytes and that is what getContentLength reports.
I also checked the streeam for good() and bad() states and it was definitely good. The length of the stream was 0 as expected.

Posts: 1375
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: HTTPClientSession.receiveResponse empty istream with c++

Postby alex » 19 Jul 2013, 17:39

GitHub issue 239.

Return to “Support”

Who is online

Users browsing this forum: No registered users and 3 guests