示例#1
0
        /// <summary>
        /// Sends bytes.
        /// </summary>
        /// <param name="data">Byte array that contains data to send.</param>
        /// <param name="offset">Offset in data</param>
        /// <param name="length">Length of bytes to transmit</param>
        /// <param name="localEcho">Whether bytes can be repeated as local echo</param>
        private void TransmitInternal(byte[] data, int offset, int length, bool localEcho)
        {
            // Note:
            //  This method may be called from multiple threads.
            //  One is UI thread which is processing key events, and another is communication thread
            //  which is going to send back something.
            //
            //  Some IPoderosaSocket implementations have thread-safe Transmit() method, but not all.
            //  So we transmit data exclusively.
            lock (_transmitSync) {
                try {
                    if (localEcho && _settings.LocalEcho)
                    {
                        _dataForLocalEcho.Set(data, 0, data.Length);
                        _host.OnReception(_dataForLocalEcho);
                    }
                    _connection.Socket.Transmit(data, offset, length);
                }
                catch (Exception) {
                    try {
                        _connection.Close();
                    }
                    catch (Exception ex) {
                        RuntimeUtil.ReportException(ex);
                    }

                    _host.TerminalHost.OwnerWindow.Warning(GEnv.Strings.GetString("Message.TerminalControl.FailedToSend"));
                }
            }
        }
示例#2
0
            //成功していることを確認し、Closeする
            public void AssertSuccess()
            {
                Assert.IsTrue(_event.WaitOne(5000, false)); //通知は受けないとだめ
                _event.Close();
                Assert.AreEqual(1, _successCount);
                Assert.AreEqual(0, _failCount);
                Assert.IsNotNull(_connection);

                _connection.Close();
            }
示例#3
0
        public void T04_SSH1Close()
        {
            ITerminalConnection con = CreateSSHConnection(SSHProtocol.SSH1);

            con.Close();
            Assert.IsTrue(con.IsClosed);
            Thread.Sleep(100);                    //非同期なのでちょっと待つ
            _testReceiver.AssertNormalTerminate();
            Assert.IsFalse(_rawsocket.Connected); //切れたこと確認
        }
示例#4
0
        public void T00_TelnetClose()
        {
            ITerminalConnection con = CreateTelnetConnection();

            Thread.Sleep(100); //Telnetはネゴシエーションが入るので、少し待って途中まで進ませる

            con.Close();
            Assert.IsTrue(con.IsClosed);
            Thread.Sleep(100);                    //非同期なのでちょっと待つ
            _testReceiver.AssertNormalTerminate();
            Assert.IsFalse(_rawsocket.Connected); //切れたこと確認
        }
        public void Transmit(byte[] data, int offset, int length)
        {
            try {
                if (_settings.LocalEcho)
                {
                    _dataForLocalEcho.Set(data, offset, length);
                    _host.OnReception(_dataForLocalEcho);
                }
                _connection.Socket.Transmit(data, offset, length);
            }catch (Exception) {
                try{
                    _connection.Close();
                }catch (Exception ex2) {               //このときに仮にエラーが発生してもユーザには通知せず
                    RuntimeUtil.ReportException(ex2);
                }

                _host.TerminalHost.OwnerWindow.Warning(GEnv.Strings.GetString("Message.TerminalControl.FailedToSend"));
            }
        }
示例#6
0
        /// <summary>
        /// <ja>
        /// ƒoƒCƒg”z—ñ‚𑗐M‚µ‚Ü‚·B
        /// </ja>
        /// <en>
        /// Send array of byte.
        /// </en>
        /// </summary>
        /// <param name="data"><ja>‘—M‚·‚éƒf[ƒ^‚ªŠi”[‚³‚ꂽƒoƒCƒg”z—ñ</ja><en>Byte array that contains data to send.</en></param>
        public void Transmit(byte[] data)
        {
            try {
                if (_settings.LocalEcho)
                {
                    _dataForLocalEcho.Set(data, 0, data.Length);
                    _host.OnReception(_dataForLocalEcho);
                }
                _connection.Socket.Transmit(data, 0, data.Length);
            }
            catch (Exception) {
                try {
                    _connection.Close();
                }
                catch (Exception ex2) { //‚±‚Ì‚Æ‚«‚ɉ¼‚ɃGƒ‰[‚ª”­¶‚µ‚Ä‚àƒ†[ƒU‚É‚Í’Ê’m‚¹‚¸
                    RuntimeUtil.ReportException(ex2);
                }

                //_host.TerminalHost.OwnerWindow.Warning("Message.TerminalControl.FailedToSend");
                Console.WriteLine("Message.TerminalControl.FailedToSend");
            }
        }