コード例 #1
0
ファイル: TerminalOutput.cs プロジェクト: saitoha/poderosa
        /// <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
        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"));
            }
        }