can be called only from asio
| 651 | |
| 652 | //can be called only from asio |
| 653 | void OnConnect(const TErrorCode& ec, IHandlingContext& ctx) { |
| 654 | DBGOUT("THttpConn::OnConnect: " << ec.Value()); |
| 655 | if (Y_UNLIKELY(ec)) { |
| 656 | if (ec.Value() == ETIMEDOUT && ConnectDeadline_.GetValue()) { |
| 657 | //detect slow connecting (yet not reached final timeout) |
| 658 | DBGOUT("OnConnectTimingCheck"); |
| 659 | THttpRequestRef req(GetRequest()); |
| 660 | if (!req) { |
| 661 | return; //cancel from client thread can ahead us |
| 662 | } |
| 663 | TDuration newDeadline(ConnectDeadline_); |
| 664 | ConnectDeadline_ = TDuration::Zero(); //next timeout is final |
| 665 | |
| 666 | req->OnDetectSlowConnecting(); |
| 667 | //continue wait connect |
| 668 | ctx.ContinueUseHandler(newDeadline); |
| 669 | |
| 670 | return; |
| 671 | } |
| 672 | #ifdef DEBUG_STAT |
| 673 | if (ec.Value() != ECANCELED) { |
| 674 | ++TDebugStat::ConnFailed; |
| 675 | } else { |
| 676 | ++TDebugStat::ConnConnCanceled; |
| 677 | } |
| 678 | #endif |
| 679 | if (ec.Value() == EIO) { |
| 680 | //try get more detail error info |
| 681 | char buf[1]; |
| 682 | TErrorCode errConnect; |
| 683 | AS_.ReadSome(buf, 1, errConnect); |
| 684 | OnConnectFailed(errConnect.Value() ? errConnect : ec); |
| 685 | } else if (ec.Value() == ECANCELED) { |
| 686 | // not try connecting to next host ip addr, simple fail |
| 687 | OnError(ec); |
| 688 | } else { |
| 689 | OnConnectFailed(ec); |
| 690 | } |
| 691 | } else { |
| 692 | Connected_ = true; |
| 693 | |
| 694 | THttpRequestRef req(GetRequest()); |
| 695 | if (!req || Canceled_) { |
| 696 | return; |
| 697 | } |
| 698 | |
| 699 | try { |
| 700 | PrepareSocket(AS_.Native(), req->RequestSettings()); |
| 701 | if (THttp2Options::TcpKeepAlive) { |
| 702 | SetKeepAlive(AS_.Native(), true); |
| 703 | } |
| 704 | } catch (TSystemError& err) { |
| 705 | TErrorCode ec2(err.Status()); |
| 706 | OnError(ec2); |
| 707 | return; |
| 708 | } |
| 709 | |
| 710 | req->OnConnect(this); |
nothing calls this directly
no test coverage detected