forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle EAGAIN in Console.Write (dotnet/corefx#23539)
If stdout/stderr is configured as a non-blocking file descriptor, Console.Write{Line} may fail if the descriptor is full and would block. With this commit, we instead poll in that case waiting for the ability to write and then retry. Commit migrated from dotnet/corefx@e84604e
- Loading branch information
1 parent
bb6abf5
commit b0b7da4
Showing
4 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/libraries/System.Console/tests/NonStandardConfiguration.Unix.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Diagnostics; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace System.Tests | ||
{ | ||
public partial class NonStandardConfigurationTests : RemoteExecutorTestBase | ||
{ | ||
[PlatformSpecific(TestPlatforms.AnyUnix)] // Uses P/Invokes | ||
[Fact] | ||
public void NonBlockingStdout_AllDataReceived() | ||
{ | ||
RemoteInvokeHandle remote = RemoteInvoke(() => | ||
{ | ||
char[] data = Enumerable.Repeat('a', 1024).ToArray(); | ||
const int StdoutFd = 1; | ||
Assert.Equal(0, Interop.Sys.Fcntl.DangerousSetIsNonBlocking((IntPtr)StdoutFd, 1)); | ||
for (int i = 0; i < 10_000; i++) | ||
{ | ||
Console.Write(data); | ||
} | ||
return SuccessExitCode; | ||
}, new RemoteInvokeOptions { StartInfo = new ProcessStartInfo() { RedirectStandardOutput = true } }); | ||
|
||
using (remote) | ||
{ | ||
Assert.Equal( | ||
new string('a', 1024 * 10_000), | ||
remote.Process.StandardOutput.ReadToEnd()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters