Skip to content

Commit

Permalink
Add documentation for standard streams blocking behaviour (#14577)
Browse files Browse the repository at this point in the history
Co-authored-by: Beta Ziliani <[email protected]>
  • Loading branch information
straight-shoota and beta-ziliani authored May 13, 2024
1 parent bf39878 commit 12f4e03
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/kernel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ require "crystal/at_exit_handlers"
{% end %}

# The standard input file descriptor. Contains data piped to the program.
#
# On Unix systems, if the file descriptor is a TTY, the runtime duplicates it.
# So `STDIN.fd` might not be `0`.
# The reason for this is to enable non-blocking reads for concurrency. Other fibers
# can run while waiting on user input. The original file descriptor is
# inherited from the parent process. Setting it to non-blocking mode would
# reflect back, which can cause problems.
#
# On Windows, `STDIN` is always blocking.
STDIN = IO::FileDescriptor.from_stdio(0)

# The standard output file descriptor.
Expand All @@ -22,6 +31,15 @@ STDIN = IO::FileDescriptor.from_stdio(0)
# This is convenient but slower than with `flush_on_newline` set to `false`.
# If you need a bit more performance and you don't care about near real-time
# output you can do `STDOUT.flush_on_newline = false`.
#
# On Unix systems, if the file descriptor is a TTY, the runtime duplicates it.
# So `STDOUT.fd` might not be `1`.
# The reason for this is to enable non-blocking writes for concurrency. Other fibers
# can run while waiting on IO. The original file descriptor is
# inherited from the parent process. Setting it to non-blocking mode would
# reflect back which can cause problems.
#
# On Windows, `STDOUT` is always blocking.
STDOUT = IO::FileDescriptor.from_stdio(1)

# The standard error file descriptor.
Expand All @@ -39,6 +57,15 @@ STDOUT = IO::FileDescriptor.from_stdio(1)
# This is convenient but slower than with `flush_on_newline` set to `false`.
# If you need a bit more performance and you don't care about near real-time
# output you can do `STDERR.flush_on_newline = false`.
#
# On Unix systems, if the file descriptor is a TTY, the runtime duplicates it.
# So `STDERR.fd` might not be `2`.
# The reason for this is to enable non-blocking writes for concurrency. Other fibers
# can run while waiting on IO. The original file descriptor is
# inherited from the parent process. Setting it to non-blocking mode would
# reflect back which can cause problems.
#
# On Windows, `STDERR` is always blocking.
STDERR = IO::FileDescriptor.from_stdio(2)

# The name, the program was called with.
Expand Down

0 comments on commit 12f4e03

Please sign in to comment.