Ejemplo n.º 1
0
        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);
                }
            }
        }