called from client thread
| 638 | |
| 639 | //called from client thread |
| 640 | bool Run(TRequestRef& req) { |
| 641 | if (Y_UNLIKELY(AtomicGet(State_) == Closed)) { |
| 642 | return false; |
| 643 | } |
| 644 | |
| 645 | req->Ref(); |
| 646 | try { |
| 647 | Reqs_.Enqueue(req.Get()); |
| 648 | } catch (...) { |
| 649 | req->UnRef(); |
| 650 | throw; |
| 651 | } |
| 652 | |
| 653 | NeedCheckReqsQueue_.store(true); |
| 654 | req->SetConnection(this); |
| 655 | TAtomicBase state = AtomicGet(State_); |
| 656 | if (Y_LIKELY(state == Connected)) { |
| 657 | ProcessOutputReqsQueue(); |
| 658 | return true; |
| 659 | } |
| 660 | |
| 661 | if (state == Init) { |
| 662 | if (AtomicCas(&State_, Connecting, Init)) { |
| 663 | try { |
| 664 | TEndpoint addr(new NAddr::TAddrInfo(&*req->Addr()->Addr.Begin())); |
| 665 | AS_.AsyncConnect(addr, std::bind(&TConnection::OnConnect, TConnectionRef(this), _1, _2), TTcp2Options::ConnectTimeout); |
| 666 | } catch (...) { |
| 667 | AS_.GetIOService().Post(std::bind(&TConnection::OnErrorCallback, TConnectionRef(this), CurrentExceptionMessage())); |
| 668 | } |
| 669 | return true; |
| 670 | } |
| 671 | } |
| 672 | state = AtomicGet(State_); |
| 673 | if (state == Connected) { |
| 674 | ProcessOutputReqsQueue(); |
| 675 | } else if (state == Closed) { |
| 676 | SafeOnError(); |
| 677 | } |
| 678 | return true; |
| 679 | } |
| 680 | |
| 681 | //called from client thread |
| 682 | void Cancel(TRequestId id) { |
nothing calls this directly
no test coverage detected