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

Function ReadOneResponse

test/brpc_http_rpc_protocol_unittest.cpp:2002–2030  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2000#undef BRPC_CRLF
2001
2002void ReadOneResponse(brpc::SocketUniquePtr& sock,
2003 brpc::DestroyingPtr<brpc::policy::HttpContext>& imsg_guard) {
2004#if defined(OS_LINUX)
2005 ASSERT_EQ(0, bthread_fd_wait(sock->fd(), EPOLLIN));
2006#elif defined(OS_MACOSX)
2007 ASSERT_EQ(0, bthread_fd_wait(sock->fd(), EVFILT_READ));
2008#endif
2009
2010 butil::IOPortal read_buf;
2011 int64_t start_time = butil::cpuwide_time_us();
2012 while (true) {
2013 const ssize_t nr = read_buf.append_from_file_descriptor(sock->fd(), 4096);
2014 LOG(INFO) << "nr=" << nr;
2015 LOG(INFO) << butil::ToPrintableString(read_buf);
2016 ASSERT_TRUE(nr > 0 || (nr < 0 && errno == EAGAIN));
2017 if (errno == EAGAIN) {
2018 ASSERT_LT(butil::cpuwide_time_us(), start_time + 1000000L) << "Too long!";
2019 bthread_usleep(1000);
2020 continue;
2021 }
2022 brpc::ParseResult pr = brpc::policy::ParseHttpMessage(&read_buf, sock.get(), false, NULL);
2023 ASSERT_TRUE(pr.error() == brpc::PARSE_ERROR_NOT_ENOUGH_DATA || pr.is_ok());
2024 if (pr.is_ok()) {
2025 imsg_guard.reset(static_cast<brpc::policy::HttpContext*>(pr.message()));
2026 break;
2027 }
2028 }
2029 ASSERT_TRUE(read_buf.empty());
2030}
2031
2032TEST_F(HttpTest, http_expect) {
2033 const int port = 8923;

Callers 1

TEST_FFunction · 0.85

Calls 13

bthread_fd_waitFunction · 0.85
cpuwide_time_usFunction · 0.85
ToPrintableStringFunction · 0.85
bthread_usleepFunction · 0.85
ParseHttpMessageFunction · 0.85
fdMethod · 0.45
getMethod · 0.45
errorMethod · 0.45
is_okMethod · 0.45
resetMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected