Skip to content

Commit

Permalink
2004-09-07 Dick Porter <dick@ximian.com>
Browse files Browse the repository at this point in the history
	* Process.cs: Throw documented exceptions when getting stdin,
	stdout or stderr and they haven't been redirected.  Check that
	CreatePipe didn't fail, throw exceptions if it did.  Close
	redirected streams when the process is disposed, rather than rely
	on the GC disposing them later.  Makes timeline much happier,
	because it could run out of file descriptors between GC
	collections.

svn path=/branches/mono-1-0/mcs/; revision=33502
  • Loading branch information
dickp committed Sep 7, 2004
1 parent 9984dde commit 7a2d37d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mcs/class/System/System.Diagnostics/ChangeLog
@@ -1,3 +1,13 @@
2004-09-07 Dick Porter <dick@ximian.com>

* Process.cs: Throw documented exceptions when getting stdin,
stdout or stderr and they haven't been redirected. Check that
CreatePipe didn't fail, throw exceptions if it did. Close
redirected streams when the process is disposed, rather than rely
on the GC disposing them later. Makes timeline much happier,
because it could run out of file descriptors between GC
collections.

2004-09-06 Dick Porter <dick@ximian.com>

* Process.cs: Make Dispose() actually dispose things.
Expand Down
36 changes: 36 additions & 0 deletions mcs/class/System/System.Diagnostics/Process.cs
Expand Up @@ -460,6 +460,10 @@ private struct ProcInfo
[MonitoringDescription ("The standard error stream of this process.")]
public StreamReader StandardError {
get {
if (error_stream == null) {
throw new InvalidOperationException("Standard error has not been redirected");
}

return(error_stream);
}
}
Expand All @@ -470,6 +474,10 @@ private struct ProcInfo
[MonitoringDescription ("The standard input stream of this process.")]
public StreamWriter StandardInput {
get {
if (input_stream == null) {
throw new InvalidOperationException("Standard input has not been redirected");
}

return(input_stream);
}
}
Expand All @@ -480,6 +488,10 @@ private struct ProcInfo
[MonitoringDescription ("The standard output stream of this process.")]
public StreamReader StandardOutput {
get {
if (output_stream == null) {
throw new InvalidOperationException("Standard output has not been redirected");
}

return(output_stream);
}
}
Expand Down Expand Up @@ -739,6 +751,9 @@ public void Kill ()
if(startInfo.RedirectStandardInput==true) {
ret=MonoIO.CreatePipe(out stdin_rd,
out stdin_wr);
if (ret == false) {
throw new IOException("Error creating standard input pipe");
}
} else {
stdin_rd=MonoIO.ConsoleInput;
/* This is required to stop the
Expand All @@ -751,6 +766,9 @@ public void Kill ()
if(startInfo.RedirectStandardOutput==true) {
ret=MonoIO.CreatePipe(out stdout_rd,
out stdout_wr);
if (ret == false) {
throw new IOException("Error creating standard output pipe");
}
} else {
stdout_rd=(IntPtr)0;
stdout_wr=MonoIO.ConsoleOutput;
Expand All @@ -759,6 +777,9 @@ public void Kill ()
if(startInfo.RedirectStandardError==true) {
ret=MonoIO.CreatePipe(out stderr_rd,
out stderr_wr);
if (ret == false) {
throw new IOException("Error creating standard error pipe");
}
} else {
stderr_rd=(IntPtr)0;
stderr_wr=MonoIO.ConsoleError;
Expand Down Expand Up @@ -922,6 +943,21 @@ public void Kill ()
Process_free_internal(process_handle);
process_handle=IntPtr.Zero;
}

if (input_stream != null) {
input_stream.Close();
input_stream = null;
}

if (output_stream != null) {
output_stream.Close();
output_stream = null;
}

if (error_stream != null) {
error_stream.Close();
error_stream = null;
}
}
}
base.Dispose (disposing);
Expand Down

0 comments on commit 7a2d37d

Please sign in to comment.