Skip to content

Commit

Permalink
Add IO::FileDescriptor::Handle (#14390)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Mar 25, 2024
1 parent 10e354f commit 5a8574b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/crystal/system/unix/file_descriptor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ require "termios"
module Crystal::System::FileDescriptor
include IO::Evented

@volatile_fd : Atomic(Int32)
# Platform-specific type to represent a file descriptor handle to the operating
# system.
alias Handle = Int32

private def unbuffered_read(slice : Bytes) : Int32
evented_read(slice, "Error reading file") do
Expand Down
5 changes: 4 additions & 1 deletion src/crystal/system/win32/file_descriptor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ require "io/overlapped"
module Crystal::System::FileDescriptor
include IO::Overlapped

@volatile_fd : Atomic(LibC::Int)
# Platform-specific type to represent a file descriptor handle to the operating
# system.
alias Handle = ::LibC::Int

@system_blocking = true

private def unbuffered_read(slice : Bytes) : Int32
Expand Down
7 changes: 4 additions & 3 deletions src/io/file_descriptor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ class IO::FileDescriptor < IO
include Crystal::System::FileDescriptor
include IO::Buffered

# The raw file-descriptor. It is defined to be an `Int`, but its size is
# platform-specific.
def fd : Int
@volatile_fd : Atomic(Handle)

# Returns the raw file-descriptor handle. Its type is platform-specific.
def fd : Handle
@volatile_fd.get
end

Expand Down

0 comments on commit 5a8574b

Please sign in to comment.