MCPcopy Create free account
hub / github.com/apache/brpc / Download

Method Download

test/brpc_http_rpc_protocol_unittest.cpp:559–605  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

557 , _last_errno(0) {}
558
559 void Download(::google::protobuf::RpcController* cntl_base,
560 const ::test::HttpRequest*,
561 ::test::HttpResponse*,
562 ::google::protobuf::Closure* done) {
563 brpc::ClosureGuard done_guard(done);
564 brpc::Controller* cntl =
565 static_cast<brpc::Controller*>(cntl_base);
566 cntl->http_response().set_content_type("text/plain");
567 brpc::StopStyle stop_style = (_nrep == std::numeric_limits<size_t>::max()
568 ? brpc::FORCE_STOP : brpc::WAIT_FOR_STOP);
569 butil::intrusive_ptr<brpc::ProgressiveAttachment> pa
570 = cntl->CreateProgressiveAttachment(stop_style);
571 if (pa == NULL) {
572 cntl->SetFailed("The socket was just failed");
573 return;
574 }
575 if (_done_place == DONE_BEFORE_CREATE_PA) {
576 done_guard.reset(NULL);
577 }
578 ASSERT_GT(PA_DATA_LEN, 8u); // long enough to hold a 64-bit decimal.
579 char buf[PA_DATA_LEN];
580 for (size_t c = 0; c < _nrep;) {
581 CopyPAPrefixedWithSeqNo(buf, c);
582 if (pa->Write(buf, sizeof(buf)) != 0) {
583 if (errno == brpc::EOVERCROWDED) {
584 LOG_EVERY_SECOND(INFO) << "full pa=" << pa.get();
585 _ever_full = true;
586 bthread_usleep(10000);
587 continue;
588 } else {
589 _last_errno = errno;
590 break;
591 }
592 } else {
593 _nwritten += PA_DATA_LEN;
594 }
595 ++c;
596 }
597 if (_done_place == DONE_AFTER_CREATE_PA_BEFORE_DESTROY_PA) {
598 done_guard.reset(NULL);
599 }
600 LOG(INFO) << "Destroy pa=" << pa.get();
601 pa.reset(NULL);
602 if (_done_place == DONE_AFTER_DESTROY_PA) {
603 done_guard.reset(NULL);
604 }
605 }
606
607 void DownloadFailed(::google::protobuf::RpcController* cntl_base,
608 const ::test::HttpRequest*,

Callers

nothing calls this directly

Calls 8

CopyPAPrefixedWithSeqNoFunction · 0.85
bthread_usleepFunction · 0.85
set_content_typeMethod · 0.80
SetFailedMethod · 0.45
resetMethod · 0.45
WriteMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected