void HttpClientImpl::onReplyFinished(http::Client& client) { log_debug("onReplyFinished; method=" << static_cast<void*>(_proc)); try { _exceptionPending = false; endCall(); } catch (const std::exception& e) { if (!_proc) throw; _exceptionPending = true; IRemoteProcedure* proc = _proc; _proc = 0; proc->onFinished(); _exceptionPending = false; return; } IRemoteProcedure* proc = _proc; _proc = 0; proc->onFinished(); }
void RpcClientImpl::onOutput(StreamBuffer& sb) { try { _exceptionPending = false; sb.endWrite(); if (sb.out_avail() > 0) sb.beginWrite(); else sb.beginRead(); } catch (const std::exception&) { IRemoteProcedure* proc = _proc; cancel(); if (!proc) throw; _exceptionPending = true; proc->onFinished(); if (_exceptionPending) throw; } }
void RpcClientImpl::onSslConnect(net::TcpSocket& socket) { try { log_trace("onSslConnect"); _exceptionPending = false; socket.endSslConnect(); _stream.buffer().beginWrite(); } catch (const std::exception& ) { IRemoteProcedure* proc = _proc; cancel(); if (!proc) throw; _exceptionPending = true; proc->onFinished(); if (_exceptionPending) throw; } }
void RpcClientImpl::onInput(StreamBuffer& sb) { try { _exceptionPending = false; sb.endRead(); if (sb.device()->eof()) throw IOError("end of input"); while (_stream.buffer().in_avail()) { char ch = StreamBuffer::traits_type::to_char_type(_stream.buffer().sbumpc()); if (_scanner.advance(ch)) { _scanner.finish(); IRemoteProcedure* proc = _proc; _proc = 0; proc->onFinished(); return; } } if (!_stream) { close(); throw std::runtime_error("reading result failed"); } sb.beginRead(); } catch (const std::exception&) { IRemoteProcedure* proc = _proc; cancel(); if (!proc) throw; _exceptionPending = true; proc->onFinished(); if (_exceptionPending) throw; } }
void RpcClientImpl::beginCall(IComposer& r, IRemoteProcedure& method, IDecomposer** argv, unsigned argc) { if (_socket.selector() == 0) throw std::logic_error("cannot run async rpc request without a selector"); if (_proc) throw std::logic_error("asyncronous request already running"); _proc = &method; prepareRequest(method.name(), argv, argc); try { if (_socket.isConnected()) { try { _stream.buffer().beginWrite(); } catch (const IOError&) { log_debug("write failed, connection is not active any more"); _socket.beginConnect(_addrInfo); } } else { log_debug("not yet connected - do it now"); _socket.beginConnect(_addrInfo); } } catch (const std::exception& ) { IRemoteProcedure* proc = _proc; cancel(); _exceptionPending = true; proc->onFinished(); if (_exceptionPending) throw; } _scanner.begin(_deserializer, r); }