是否在EOF UB之后读取?

时间:2019-07-01 15:46:18

标签: c++ boost poco-libraries streambuf

我尝试结合Poco和boost :: iostreams :: filtering_stream,发现两个问题:

  1. Poco::Net::HTTPChunkedStreamBuf::underflow仅在会话关闭后才返回EOF。
  2. boost::iostreams::detail:indirect_streambuf::underflow:返回值基于成功读取的符号数。

Poco::Net::HTTPChunkedStreamBuf::underflow是否必须在会话关闭后重复返回EOF或在这种情况下返回值未定义?

仅从boost::iostreams::detail::indirect_streambuf::underflow读取0个符号还是从streambuf返回EOF还是应该检查sgetc()的EOF并在这种情况下返回EOF是正确的?

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";
    }
};

如果运行此命令,我将冻结:

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

我发现,如果过滤流的缓冲区大小为0,则不会冻结。

0 个答案:

没有答案