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

Method ProcessRpcRequest

test/brpc_channel_unittest.cpp:257–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255 }
256
257 static void ProcessRpcRequest(brpc::InputMessageBase* msg_base) {
258 brpc::DestroyingPtr<brpc::policy::MostCommonMessage> msg(
259 static_cast<brpc::policy::MostCommonMessage*>(msg_base));
260 brpc::SocketUniquePtr ptr(msg->ReleaseSocket());
261 const brpc::AuthContext* auth = ptr->auth_context();
262 if (auth) {
263 EXPECT_EQ(MOCK_CONTEXT, auth->user());
264 EXPECT_EQ(MOCK_CONTEXT, auth->group());
265 EXPECT_EQ(MOCK_CONTEXT, auth->roles());
266 EXPECT_EQ(MOCK_CONTEXT, auth->starter());
267 EXPECT_TRUE(auth->is_service());
268 }
269 ChannelTest* ts = (ChannelTest*)msg_base->arg();
270 if (ts->_close_fd_once) {
271 ts->_close_fd_once = false;
272 ptr->SetFailed();
273 return;
274 }
275
276 brpc::policy::RpcMeta meta;
277 butil::IOBufAsZeroCopyInputStream wrapper(msg->meta);
278 EXPECT_TRUE(meta.ParseFromZeroCopyStream(&wrapper));
279 const brpc::policy::RpcRequestMeta& req_meta = meta.request();
280 ASSERT_EQ(ts->_svc.descriptor()->full_name(), req_meta.service_name());
281 const google::protobuf::MethodDescriptor* method =
282 ts->_svc.descriptor()->FindMethodByName(req_meta.method_name());
283 brpc::RpcPBMessages* messages =
284 ts->_dummy.options().rpc_pb_message_factory->Get(ts->_svc, *method);
285 google::protobuf::Message* req = messages->Request();
286 google::protobuf::Message* res = messages->Response();
287 if (meta.attachment_size() != 0) {
288 butil::IOBuf req_buf;
289 msg->payload.cutn(&req_buf, msg->payload.size() - meta.attachment_size());
290 butil::IOBufAsZeroCopyInputStream wrapper2(req_buf);
291 EXPECT_TRUE(req->ParseFromZeroCopyStream(&wrapper2));
292 } else {
293 butil::IOBufAsZeroCopyInputStream wrapper2(msg->payload);
294 EXPECT_TRUE(req->ParseFromZeroCopyStream(&wrapper2));
295 }
296 brpc::Controller* cntl = new brpc::Controller();
297 cntl->_current_call.peer_id = ptr->id();
298 cntl->_current_call.sending_sock.reset(ptr.release());
299 cntl->_server = &ts->_dummy;
300
301 google::protobuf::Closure* done = brpc::NewCallback<
302 int64_t, brpc::Controller*, brpc::RpcPBMessages*, const brpc::Server*,
303 brpc::MethodStatus*, int64_t, std::shared_ptr<brpc::Span>>(
304 &brpc::policy::SendRpcResponse, meta.correlation_id(), cntl,
305 messages, &ts->_dummy, NULL, -1, nullptr);
306 ts->_svc.CallMethod(method, cntl, req, res, done);
307 }
308
309 int StartAccept(butil::EndPoint ep) {
310 int listening_fd = -1;

Callers

nothing calls this directly

Calls 15

ReleaseSocketMethod · 0.80
auth_contextMethod · 0.80
is_serviceMethod · 0.80
argMethod · 0.80
descriptorMethod · 0.80
service_nameMethod · 0.80
optionsMethod · 0.80
correlation_idMethod · 0.80
SetFailedMethod · 0.45
GetMethod · 0.45
RequestMethod · 0.45
ResponseMethod · 0.45

Tested by

no test coverage detected