/// <summary> /// We wait new connection from IRpcHandlers in this thread /// </summary> private void HandlerThread() { mHandlerListener.Start(); while (true) { try { var client = mHandlerListener.AcceptTcpClient(); var module = new RpcHandler { RequestGuardtime = new TimeSpan(0, 5, 0) }; // 5 minute is default module.Handler(client); AddHandler(module); if (mLogger != null) { mLogger.Debug("IRpcHandler connection request received"); } Thread.Sleep(200); } catch (ThreadAbortException) { mHandlerListener.Stop(); throw; } catch (Exception ex) { if (!(ex is SocketException || ex is IOException || ex is InvalidOperationException)) { if (mLogger != null) { mLogger.Warn("Unexpected exception " + ex.GetType() + " at HandlerThread " + ex.Message); } } } } }
private void ProcessingThread() { while (true) { var client = new TcpClient { SendTimeout = 3 * 60 * 1000 }; // таймаут на отправку данных на сервер try { client.Connect(mHost, mPort); if (!client.Connected) { client.Close(); continue; } // yahoo, we have connected tcp client mRpcHandler.Handler(client); mRpcHandler.RequestGuardtime = mRequestGuardtime; mProxyUpdated = false; while (mRpcHandler.IsActive && !mProxyUpdated) { // get our request and process here var request = mRpcHandler.GetRequest(); if (request != null) { if (mProxy != null) { mRpcHandler.SendResponse(mProxy.Invoke(request)); } } Thread.Sleep(50); } mRpcHandler.Dispose(); } catch (ThreadAbortException) { mRpcHandler.Dispose(); client.Close(); throw; } catch (Exception ex) { if (mLogger != null) { if (!(ex is SocketException || ex is IOException || ex is ObjectDisposedException)) { mLogger.Warn("Unexpected exception " + ex.GetType() + " at ConnectionThread " + ex.Message); } else { mLogger.Debug("Expected exception " + ex.GetType() + " at ConnectionThread " + ex.Message); } } // timeout for re-connection Thread.Sleep(ReconnectionTimeout); } } }