/// <summary> /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device. /// </summary> /// <exception cref="T:System.IO.IOException">An I/O error occurs.</exception> public override void Flush() { if (_channel == null) { throw new ObjectDisposedException("ShellStream"); } _channel.SendData(_outgoing.ToArray()); _outgoing.Clear(); }
private void SendData(IChannelSession channel, byte[] buffer, int length) { if (length == buffer.Length) { channel.SendData(buffer); } else { channel.SendData(buffer.Take(length).ToArray()); } }
private void SendData(IChannelSession channel, byte[] buffer, int length) { #if TUNING channel.SendData(buffer, 0, length); #else if (length == buffer.Length) { channel.SendData(buffer); } else { channel.SendData(buffer.Take(length).ToArray()); } #endif }
/// <summary> /// Sends data to the subsystem. /// </summary> /// <param name="data">The data to be sent.</param> public void SendData(byte[] data) { EnsureNotDisposed(); EnsureSessionIsOpen(); _channel.SendData(data); }
/// <summary> /// Starts this shell. /// </summary> /// <exception cref="SshException">Shell is started.</exception> public void Start() { if (IsStarted) { throw new SshException("Shell is started."); } if (Starting != null) { Starting(this, new EventArgs()); } _channel = _session.CreateChannelSession(); _channel.DataReceived += Channel_DataReceived; _channel.ExtendedDataReceived += Channel_ExtendedDataReceived; _channel.Closed += Channel_Closed; _session.Disconnected += Session_Disconnected; _session.ErrorOccured += Session_ErrorOccured; _channel.Open(); _channel.SendPseudoTerminalRequest(_terminalName, _columns, _rows, _width, _height, _terminalModes); _channel.SendShellRequest(); _channelClosedWaitHandle = new AutoResetEvent(false); // Start input stream listener _dataReaderTaskCompleted = new ManualResetEvent(false); ThreadAbstraction.ExecuteThread(() => { try { var buffer = new byte[_bufferSize]; while (_channel.IsOpen) { #if FEATURE_STREAM_TAP var readTask = _input.ReadAsync(buffer, 0, buffer.Length); var readWaitHandle = ((IAsyncResult)readTask).AsyncWaitHandle; if (WaitHandle.WaitAny(new[] { readWaitHandle, _channelClosedWaitHandle }) == 0) { var read = readTask.Result; _channel.SendData(buffer, 0, read); continue; } #elif FEATURE_STREAM_APM var asyncResult = _input.BeginRead(buffer, 0, buffer.Length, result => { // If input stream is closed and disposed already don't finish reading the stream if (_input == null) { return; } var read = _input.EndRead(result); _channel.SendData(buffer, 0, read); }, null); WaitHandle.WaitAny(new[] { asyncResult.AsyncWaitHandle, _channelClosedWaitHandle }); if (asyncResult.IsCompleted) { continue; } #else #error Async receive is not implemented. #endif break; } } catch (Exception exp) { RaiseError(new ExceptionEventArgs(exp)); } finally { _dataReaderTaskCompleted.Set(); } }); IsStarted = true; if (Started != null) { Started(this, new EventArgs()); } }
private void SendData(IChannelSession channel, byte[] buffer) { channel.SendData(buffer); }
partial void SendData(IChannelSession channel, string command) { channel.SendData(Encoding.UTF8.GetBytes(command)); }
partial void SendData(IChannelSession channel, string command) { channel.SendData(Encoding.Default.GetBytes(command)); }
partial void SendData(IChannelSession channel, string command) { channel.SendData(System.Text.Encoding.Default.GetBytes(command)); }
/// <summary> /// Starts this shell. /// </summary> /// <exception cref="SshException">Shell is started.</exception> public void Start() { if (IsStarted) { throw new SshException("Shell is started."); } if (Starting != null) { Starting(this, new EventArgs()); } _channel = _session.CreateChannelSession(); _channel.DataReceived += Channel_DataReceived; _channel.ExtendedDataReceived += Channel_ExtendedDataReceived; _channel.Closed += Channel_Closed; _session.Disconnected += Session_Disconnected; _session.ErrorOccured += Session_ErrorOccured; _channel.Open(); _channel.SendPseudoTerminalRequest(_terminalName, _columns, _rows, _width, _height, _terminalModes); _channel.SendShellRequest(); _channelClosedWaitHandle = new AutoResetEvent(false); // Start input stream listener _dataReaderTaskCompleted = new ManualResetEvent(false); ThreadAbstraction.ExecuteThread(() => { try { var buffer = new byte[_bufferSize]; while (_channel.IsOpen) { #if FEATURE_STREAM_TAP var readTask = _input.ReadAsync(buffer, 0, buffer.Length); var readWaitHandle = ((IAsyncResult) readTask).AsyncWaitHandle; if (WaitHandle.WaitAny(new[] {readWaitHandle, _channelClosedWaitHandle}) == 0) { var read = readTask.Result; _channel.SendData(buffer, 0, read); continue; } #elif FEATURE_STREAM_APM var asyncResult = _input.BeginRead(buffer, 0, buffer.Length, result => { // If input stream is closed and disposed already don't finish reading the stream if (_input == null) return; var read = _input.EndRead(result); _channel.SendData(buffer, 0, read); }, null); WaitHandle.WaitAny(new[] { asyncResult.AsyncWaitHandle, _channelClosedWaitHandle }); if (asyncResult.IsCompleted) continue; #else #error Async receive is not implemented. #endif break; } } catch (Exception exp) { RaiseError(new ExceptionEventArgs(exp)); } finally { _dataReaderTaskCompleted.Set(); } }); IsStarted = true; if (Started != null) { Started(this, new EventArgs()); } }
/// <summary> /// Starts this shell. /// </summary> /// <exception cref="SshException">Shell is started.</exception> public void Start() { if (IsStarted) { throw new SshException("Shell is started."); } if (Starting != null) { Starting(this, new EventArgs()); } _channel = _session.CreateChannelSession(); _channel.DataReceived += Channel_DataReceived; _channel.ExtendedDataReceived += Channel_ExtendedDataReceived; _channel.Closed += Channel_Closed; _session.Disconnected += Session_Disconnected; _session.ErrorOccured += Session_ErrorOccured; _channel.Open(); _channel.SendPseudoTerminalRequest(_terminalName, _columns, _rows, _width, _height, _terminalModes); _channel.SendShellRequest(); _channelClosedWaitHandle = new AutoResetEvent(false); // Start input stream listener _dataReaderTaskCompleted = new ManualResetEvent(false); ExecuteThread(() => { try { var buffer = new byte[_bufferSize]; while (_channel.IsOpen) { var asyncResult = _input.BeginRead(buffer, 0, buffer.Length, delegate(IAsyncResult result) { // If input stream is closed and disposed already dont finish reading the stream if (_input == null) return; var read = _input.EndRead(result); if (read > 0) { #if TUNING _channel.SendData(buffer, 0, read); #else _channel.SendData(buffer.Take(read).ToArray()); #endif } }, null); EventWaitHandle.WaitAny(new WaitHandle[] { asyncResult.AsyncWaitHandle, _channelClosedWaitHandle }); if (asyncResult.IsCompleted) continue; break; } } catch (Exception exp) { RaiseError(new ExceptionEventArgs(exp)); } finally { _dataReaderTaskCompleted.Set(); } }); IsStarted = true; if (Started != null) { Started(this, new EventArgs()); } }
/// <summary> /// Starts this shell. /// </summary> /// <exception cref="SshException">Shell is started.</exception> public void Start() { if (IsStarted) { throw new SshException("Shell is started."); } if (Starting != null) { Starting(this, new EventArgs()); } _channel = _session.CreateChannelSession(); _channel.DataReceived += Channel_DataReceived; _channel.ExtendedDataReceived += Channel_ExtendedDataReceived; _channel.Closed += Channel_Closed; _session.Disconnected += Session_Disconnected; _session.ErrorOccured += Session_ErrorOccured; _channel.Open(); _channel.SendPseudoTerminalRequest(_terminalName, _columns, _rows, _width, _height, _terminalModes); _channel.SendShellRequest(); _channelClosedWaitHandle = new AutoResetEvent(false); // Start input stream listener _dataReaderTaskCompleted = new ManualResetEvent(false); ExecuteThread(async() => { try { var buffer = new byte[_bufferSize]; while (_channel.IsOpen) { var read = await _input.ReadAsync(buffer, 0, buffer.Length); if (read > 0) { #if true //old TUNING _channel.SendData(buffer, 0, read); #else _channel.SendData(buffer.Take(read).ToArray()); #endif } if (_channelClosedWaitHandle.WaitOne(0)) { break; } } } catch (Exception exp) { RaiseError(new ExceptionEventArgs(exp)); } finally { _dataReaderTaskCompleted.Set(); } }); IsStarted = true; if (Started != null) { Started(this, new EventArgs()); } }
/// <summary> /// Starts this shell. /// </summary> /// <exception cref="SshException">Shell is started.</exception> public void Start() { if (IsStarted) { throw new SshException("Shell is started."); } if (Starting != null) { Starting(this, new EventArgs()); } _channel = _session.CreateChannelSession(); _channel.DataReceived += Channel_DataReceived; _channel.ExtendedDataReceived += Channel_ExtendedDataReceived; _channel.Closed += Channel_Closed; _session.Disconnected += Session_Disconnected; _session.ErrorOccured += Session_ErrorOccured; _channel.Open(); _channel.SendPseudoTerminalRequest(_terminalName, _columns, _rows, _width, _height, _terminalModes); _channel.SendShellRequest(); _channelClosedWaitHandle = new AutoResetEvent(false); // Start input stream listener _dataReaderTaskCompleted = new ManualResetEvent(false); ExecuteThread(() => { try { var buffer = new byte[_bufferSize]; while (_channel.IsOpen) { var asyncResult = _input.BeginRead(buffer, 0, buffer.Length, delegate(IAsyncResult result) { // If input stream is closed and disposed already dont finish reading the stream if (_input == null) { return; } var read = _input.EndRead(result); if (read > 0) { #if TUNING _channel.SendData(buffer, 0, read); #else _channel.SendData(buffer.Take(read).ToArray()); #endif } }, null); EventWaitHandle.WaitAny(new WaitHandle[] { asyncResult.AsyncWaitHandle, _channelClosedWaitHandle }); if (asyncResult.IsCompleted) { continue; } break; } } catch (Exception exp) { RaiseError(new ExceptionEventArgs(exp)); } finally { _dataReaderTaskCompleted.Set(); } }); IsStarted = true; if (Started != null) { Started(this, new EventArgs()); } }