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

Function ProcessNsheadResponse

src/brpc/policy/nshead_protocol.cpp:356–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

354}
355
356void ProcessNsheadResponse(InputMessageBase* msg_base) {
357 const int64_t start_parse_us = butil::cpuwide_time_us();
358 DestroyingPtr<MostCommonMessage> msg(static_cast<MostCommonMessage*>(msg_base));
359
360 // Fetch correlation id that we saved before in `PackNsheadRequest'
361 const CallId cid = { static_cast<uint64_t>(msg->socket()->correlation_id()) };
362 Controller* cntl = NULL;
363 const int rc = bthread_id_lock(cid, (void**)&cntl);
364 if (rc != 0) {
365 LOG_IF(ERROR, rc != EINVAL && rc != EPERM)
366 << "Fail to lock correlation_id=" << cid << ": " << berror(rc);
367 return;
368 }
369
370 ControllerPrivateAccessor accessor(cntl);
371 if (auto span = accessor.span()) {
372 span->set_base_real_us(msg->base_real_us());
373 span->set_received_us(msg->received_us());
374 span->set_response_size(msg->payload.length());
375 span->set_start_parse_us(start_parse_us);
376 }
377 // MUST be NsheadMessage (checked in SerializeNsheadRequest)
378 NsheadMessage* response = (NsheadMessage*)cntl->response();
379 const int saved_error = cntl->ErrorCode();
380 if (response != NULL) {
381 msg->meta.copy_to(&response->head, sizeof(nshead_t));
382 msg->payload.swap(response->body);
383 } // else just ignore the response.
384
385 // Unlocks correlation_id inside. Revert controller's
386 // error code if it version check of `cid' fails
387 msg.reset(); // optional, just release resource ASAP
388 accessor.OnResponse(cid, saved_error);
389}
390
391bool VerifyNsheadRequest(const InputMessageBase* msg_base) {
392 Server* server = (Server*)msg_base->arg();

Callers

nothing calls this directly

Calls 15

cpuwide_time_usFunction · 0.85
berrorFunction · 0.85
correlation_idMethod · 0.80
spanMethod · 0.80
set_base_real_usMethod · 0.80
base_real_usMethod · 0.80
set_response_sizeMethod · 0.80
set_start_parse_usMethod · 0.80
responseMethod · 0.80
ErrorCodeMethod · 0.80
OnResponseMethod · 0.80
socketMethod · 0.45

Tested by

no test coverage detected