zengkui commented on issue #1775: URL: https://github.com/apache/incubator-brpc/issues/1775#issuecomment-1146600281
> 试试这个接口,这是专门用来读chunked response的: https://github.com/apache/incubator-brpc/blob/master/src/brpc/progressive_reader.h > > 但此接口比较底层,获取events后需要append至一个IOBuf内然后按格式边界自行切割、使用 我参考utest里的用法写了一个简单的demo,发现还是有些问题。 这个 read body 会一直循环读取第一个create 事件的response, 也就是cout输出的都是create事件的响应,为啥这个事件会反复读取? 后续的事件的response为啥无法获取到了? ``` cpp class ReadBody : public brpc::ProgressiveReader, public brpc::SharedObject { public: ReadBody() : _destroyed(false) { butil::intrusive_ptr<ReadBody>(this).detach(); // ref } butil::Status OnReadOnePart(const void* data, size_t length) { while (length > 0) { os_.append(data, length); std::cout << os_.to_string() << std::endl; sleep(5); } return butil::Status::OK(); } void OnEndOfMessage(const butil::Status& st) { return; } bool destroyed() const { return _destroyed; } const butil::Status& destroying_status() const { return _destroying_st; } private: butil::IOBuf os_; bool _destroyed; butil::Status _destroying_st; }; void Watch(brpc::Channel& channel) { brpc::Controller cntl; cntl.http_request().uri().set_path("/v3/watch"); cntl.http_request().set_method(brpc::HTTP_METHOD_POST); butil::IOBufBuilder os; os << "{\"create_request\": {\"key\":\"Zm9v\"}}"; os.move_to(cntl.request_attachment()); // Cache-Control: no-cache std::string key = "Cache-Control"; std::string val = "no-cache"; cntl.http_request().SetHeader(key, val); cntl.response_will_be_read_progressively(); channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); LOG(INFO) << "waiting ..."; if (cntl.Failed()) { std::cerr << cntl.ErrorText() << std::endl; return; } butil::intrusive_ptr<ReadBody> reader; reader.reset(new ReadBody); cntl.ReadProgressiveAttachmentBy(reader.get()); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
