| 647 | } |
| 648 | |
| 649 | void Connection::ReadHandler(ev::io &watcher, int revents) { |
| 650 | DCHECK(reactor_thread_->IsCurrentThread()); |
| 651 | |
| 652 | DVLOG(3) << ToString() << " ReadHandler(revents=" << revents << ")"; |
| 653 | if (revents & EV_ERROR) { |
| 654 | reactor_thread_->DestroyConnection(this, Status::NetworkError(ToString() + |
| 655 | ": ReadHandler encountered an error")); |
| 656 | return; |
| 657 | } |
| 658 | last_activity_time_ = reactor_thread_->cur_time(); |
| 659 | |
| 660 | faststring extra_buf; |
| 661 | while (true) { |
| 662 | if (!inbound_) { |
| 663 | inbound_.reset(new InboundTransfer()); |
| 664 | } |
| 665 | Status status = inbound_->ReceiveBuffer(socket_.get(), &extra_buf); |
| 666 | if (PREDICT_FALSE(!status.ok())) { |
| 667 | if (status.posix_code() == ESHUTDOWN) { |
| 668 | VLOG(1) << ToString() << " shut down by remote end."; |
| 669 | } else { |
| 670 | LOG(WARNING) << ToString() << " recv error: " << status.ToString(); |
| 671 | } |
| 672 | reactor_thread_->DestroyConnection(this, status); |
| 673 | return; |
| 674 | } |
| 675 | if (!inbound_->TransferFinished()) { |
| 676 | DVLOG(3) << ToString() << ": read is not yet finished yet."; |
| 677 | return; |
| 678 | } |
| 679 | DVLOG(3) << ToString() << ": finished reading " << inbound_->data().size() << " bytes"; |
| 680 | |
| 681 | if (direction_ == CLIENT) { |
| 682 | HandleCallResponse(std::move(inbound_)); |
| 683 | } else if (direction_ == SERVER) { |
| 684 | HandleIncomingCall(std::move(inbound_)); |
| 685 | } else { |
| 686 | LOG(FATAL) << "Invalid direction: " << direction_; |
| 687 | } |
| 688 | |
| 689 | if (extra_buf.size() > 0) { |
| 690 | inbound_.reset(new InboundTransfer(std::move(extra_buf))); |
| 691 | } else { |
| 692 | break; |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | void Connection::HandleIncomingCall(unique_ptr<InboundTransfer> transfer) { |
| 698 | DCHECK(reactor_thread_->IsCurrentThread()); |
nothing calls this directly
no test coverage detected