must be called only from asio thread
| 898 | |
| 899 | //must be called only from asio thread |
| 900 | void OnReadSome(const TErrorCode& ec, size_t amount, IHandlingContext& ctx) { |
| 901 | //DBGOUT("OnReadSome(" << ec.Value() << ", " << amount << ")"); |
| 902 | if (Y_UNLIKELY(ec)) { |
| 903 | OnErrorCode(ec); |
| 904 | |
| 905 | return; |
| 906 | } |
| 907 | |
| 908 | while (1) { |
| 909 | if (Y_UNLIKELY(!amount)) { |
| 910 | OnError("tcp conn. closed"); |
| 911 | |
| 912 | return; |
| 913 | } |
| 914 | |
| 915 | try { |
| 916 | const char* buff = Buff_.Get(); |
| 917 | size_t leftBytes = amount; |
| 918 | do { |
| 919 | size_t useBytes = Msg_.LoadFrom(buff, leftBytes); |
| 920 | leftBytes -= useBytes; |
| 921 | buff += useBytes; |
| 922 | if (Msg_.IsComplete()) { |
| 923 | //DBGOUT("OnReceiveMessage(" << Msg_.BaseHeader().Id << "): " << leftBytes); |
| 924 | OnReceiveMessage(); |
| 925 | Msg_.Clear(); |
| 926 | } |
| 927 | } while (leftBytes); |
| 928 | |
| 929 | if (amount == BuffSize_) { |
| 930 | //try decrease system calls, - re-run ReadSome if has full filled buffer |
| 931 | TErrorCode ecR; |
| 932 | amount = AS_.ReadSome(Buff_.Get(), BuffSize_, ecR); |
| 933 | if (!ecR) { |
| 934 | continue; //process next input data |
| 935 | } |
| 936 | if (ecR.Value() == EAGAIN || ecR.Value() == EWOULDBLOCK) { |
| 937 | ctx.ContinueUseHandler(); |
| 938 | } else { |
| 939 | OnErrorCode(ec); |
| 940 | } |
| 941 | } else { |
| 942 | ctx.ContinueUseHandler(); |
| 943 | } |
| 944 | } catch (...) { |
| 945 | OnError(CurrentExceptionMessage()); |
| 946 | } |
| 947 | |
| 948 | return; |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | //must be called only from asio thread |
| 953 | void OnErrorCode(TErrorCode ec) { |
nothing calls this directly
no test coverage detected