Esempio n. 1
0
        private void Run()
        {
            _tcpConnected = false;
            _succeeded    = false;
            _socket       = null;

            try
            {
                _addressSet   = null;
                _errorMessage = null;
                MakeConnection();
                Debug.Assert(_socket != null);

                _errorMessage = null;
                Negotiate();

                _succeeded = true;
                ProtocolUtil.FireConnectionSucceeded(_tcpDestination);
            }
            catch (Exception ex)
            {
                if (!_interrupted)
                {
                    RuntimeUtil.DebuggerReportException(ex);
                    if (!_overridingErrorMessage)
                    {
                        _errorMessage = ex.Message;
                    }
                    ProtocolUtil.FireConnectionFailure(_tcpDestination, _errorMessage);
                }
            }
            finally
            {
                if (!_interrupted)
                {
                    if (!_succeeded && _socket != null && _socket.Connected)
                    {
                        try
                        {
                            _socket.Shutdown(SocketShutdown.Both);                             //Close()だと非同期受信してる場所で即Exceptionになってしまう
                        }
                        catch (Exception ex)
                        {                         //ここでちゃんと閉じることが出来ない場合があった
                            RuntimeUtil.SilentReportException(ex);
                        }
                    }
                    //ここで待機していたスレッドが動き出すので、その前にSocketのDisconnectはやっつけておく。同時につついたせいかソケットの動作が妙になったケースあり。
                    NotifyAsyncClient();
                }
            }
        }
Esempio n. 2
0
        private void Run()
        {
            _tcpConnected = false;
            _succeeded    = false;
            _socket       = null;

            try {
                _addressSet   = null;
                _errorMessage = null;
                MakeConnection();
                Debug.Assert(_socket != null);

                _errorMessage = null;
                Negotiate();

                _succeeded = true;
                ////ProtocolUtil.FireConnectionSucceeded((ITerminalParameter)_tcpDestination);
                //_client.SuccessfullyExit(this.Result);
            }
            catch (Exception ex) {
                if (!_interrupted)
                {
                    RuntimeUtil.DebuggerReportException(ex);
                    if (!_overridingErrorMessage)
                    {
                        _errorMessage = ex.Message;
                    }
                    ////ProtocolUtil.FireConnectionFailure((ITerminalParameter)_tcpDestination, _errorMessage);
                    //_client.ConnectionFailed(_errorMessage);
                }
            }
            finally {
                if (!_interrupted)
                {
                    if (!_succeeded && _socket != null && _socket.Connected)
                    {
                        try {
                            _socket.Shutdown(SocketShutdown.Both); //Close()‚¾‚Æ”ñ“¯ŠúŽóM‚µ‚Ä‚éêŠ‚Å‘¦Exception‚É‚È‚Á‚Ä‚µ‚Ü‚¤
                        } catch (Exception ex) {                   //‚±‚±‚Å‚¿‚á‚ñ‚ƕ‚¶‚邱‚Æ‚ªo—ˆ‚È‚¢ê‡‚ª‚ ‚Á‚½
                            RuntimeUtil.SilentReportException(ex);
                        }
                    }
                    //‚±‚±‚Å‘Ò‹@‚µ‚Ä‚¢‚½ƒXƒŒƒbƒh‚ª“®‚«o‚·‚̂ŁA‚»‚Ì‘O‚ÉSocket‚ÌDisconnect‚Í‚â‚Á‚‚¯‚Ä‚¨‚­B“¯Žž‚ɂ‚‚¢‚½‚¹‚¢‚©ƒ\ƒPƒbƒg‚Ì“®ì‚ª–­‚É‚È‚Á‚½ƒP[ƒX‚ ‚èB
                    NotifyAsyncClient();
                    if (_NetUtil != null)
                    {
                        _NetUtil = null;
                    }
                }
            }
        }