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

Method DownloadFailed

test/brpc_http_rpc_protocol_unittest.cpp:607–646  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

605 }
606
607 void DownloadFailed(::google::protobuf::RpcController* cntl_base,
608 const ::test::HttpRequest*,
609 ::test::HttpResponse*,
610 ::google::protobuf::Closure* done) {
611 brpc::ClosureGuard done_guard(done);
612 brpc::Controller* cntl =
613 static_cast<brpc::Controller*>(cntl_base);
614 cntl->http_response().set_content_type("text/plain");
615 brpc::StopStyle stop_style = (_nrep == std::numeric_limits<size_t>::max()
616 ? brpc::FORCE_STOP : brpc::WAIT_FOR_STOP);
617 butil::intrusive_ptr<brpc::ProgressiveAttachment> pa
618 = cntl->CreateProgressiveAttachment(stop_style);
619 if (pa == NULL) {
620 cntl->SetFailed("The socket was just failed");
621 return;
622 }
623 char buf[PA_DATA_LEN];
624 while (true) {
625 if (pa->Write(buf, sizeof(buf)) != 0) {
626 if (errno == brpc::EOVERCROWDED) {
627 LOG_EVERY_SECOND(INFO) << "full pa=" << pa.get();
628 bthread_usleep(10000);
629 continue;
630 } else {
631 _last_errno = errno;
632 break;
633 }
634 }
635 break;
636 }
637 // The remote client will not receive the data written to the
638 // progressive attachment when the controller failed.
639 cntl->SetFailed("Intentionally set controller failed");
640 done_guard.reset(NULL);
641
642 // Return value of Write after controller has failed should
643 // be less than zero.
644 CHECK_LT(pa->Write(buf, sizeof(buf)), 0);
645 CHECK_EQ(errno, ECANCELED);
646 }
647
648 void set_done_place(DonePlace done_place) { _done_place = done_place; }
649 size_t written_bytes() const { return _nwritten; }

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected