4

I try to combine Poco and boost::iostreams::filtering_stream and I found two problems:

  1. Poco::Net::HTTPChunkedStreamBuf::underflow returns EOF only once after session was closed.
  2. boost::iostreams::detail:indirect_streambuf::underflow: return value is based on number of successfully read symbols.

Does Poco::Net::HTTPChunkedStreamBuf::underflow must return EOF repeatedly after session close or return value in that case is undefined?

Is it correct to return EOF from boost::iostreams::detail::indirect_streambuf::underflow only if it reads 0 symbols from streambuf or it should check sgetc() for EOF and return EOF in that case?

class Handler : public HTTPRequestHandler {
  public:
    void handleRequest(HTTPServerRequest &request,
                       HTTPServerResponse &response) {
        response.setKeepAlive(request.getKeepAlive());
        response.setChunkedTransferEncoding(true);
        auto &stream = request.stream();
        boost::iostreams::filtering_stream<boost::iostreams::input> teeStream;
        teeStream.push(boost::iostreams::tee(std::cout));
        teeStream.push(stream);

        std::string payload;
        teeStream >> payload;
        std::cerr << payload;

        std::cerr << "handleRequest end" << std::endl;
        auto &ostr = response.send();
        ostr << "12345";
    }
};

I get freeze if i run this:

curl 'http://localhost:5959/' -H 'Transfer-Encoding: chunked' -d '1234'

I found that if the buffer size of the filtering stream is 0 then there is no freezes.

dahek
  • 41
  • 3
  • Unless you're talking about a standard library there is no question of undefined behaviour. Any properly written I/O API should just keep returning EOF at EOF. Whether the API you're using is properly written is another question. – user207421 Jul 02 '19 at 04:17
  • std::cin behaves that way. You can send EOF by pressing ctrl+D on linux and it don't start returning EOF repeatedly. – dahek Jul 02 '19 at 06:54

0 Answers0