| 354 | } |
| 355 | |
| 356 | void 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 | |
| 391 | bool VerifyNsheadRequest(const InputMessageBase* msg_base) { |
| 392 | Server* server = (Server*)msg_base->arg(); |
nothing calls this directly
no test coverage detected