Crystal::EventLoop::FileDescriptor - Crystal 1.20.1

# module Crystal::EventLoop::FileDescriptor

##
Direct including types

- Crystal::EventLoop

##
Defined in:

crystal/event_loop/file_descriptor.cr

##
Instance Method Summary

- #close(file_descriptor : Crystal::System::FileDescriptor) : Nil

  Closes the system fd or handle.

- #open(path : String, flags : Int32, permissions : File::Permissions, blocking : Bool | Nil) : Tuple(System::FileDescriptor::Handle, Bool) | Errno | WinError

  Opens a file at path.

- #pipe(read_blocking : Bool | Nil, write_blocking : Bool | Nil) : Tuple(IO::FileDescriptor, IO::FileDescriptor)

  Opens an unidirectional pipe.

- #read(file_descriptor : Crystal::System::FileDescriptor, slice : Bytes) : Int32

  Reads at least one byte from the file descriptor into slice.

- #reopened(file_descriptor : Crystal::System::FileDescriptor) : Nil

  Hook to react on the file descriptor after it has been reopened.

- #shutdown(file_descriptor : Crystal::System::FileDescriptor) : Nil

  Internal shutdown of the file descriptor.

- #wait_readable(file_descriptor : Crystal::System::FileDescriptor) : Nil

  Blocks the current fiber until the file descriptor is ready for read.

- #wait_writable(file_descriptor : Crystal::System::FileDescriptor) : Nil

  Blocks the current fiber until the file descriptor is ready for write.

- #write(file_descriptor : Crystal::System::FileDescriptor, slice : Bytes) : Int32

  Writes at least one byte from slice to the file descriptor.

##
Instance Method Detail

abstract def close(file_descriptor : Crystal::System::FileDescriptor) : Nil #

Closes the system fd or handle.

abstract def open(path : String, flags : Int32, permissions : File::Permissions, blocking : Bool | Nil) : Tuple(System::FileDescriptor::Handle, Bool) | Errno | WinError #

Opens a file at path.

Blocks the current fiber until the file has been opened. Avoids blocking the current thread if possible, especially when blocking is `false` or `nil`.

Returns the system file descriptor or handle, or a system error.

abstract def pipe(read_blocking : Bool | Nil, write_blocking : Bool | Nil) : Tuple(IO::FileDescriptor, IO::FileDescriptor) #

Opens an unidirectional pipe.

The implementation shall respect the specified blocking arguments for each end of the pipe, and follow its internal blocking requirements when a blocking arg is nil.

Returns a tuple with the reader and writer IO objects.

abstract def read(file_descriptor : Crystal::System::FileDescriptor, slice : Bytes) : Int32 #

Reads at least one byte from the file descriptor into slice.

Blocks the current fiber if no data is available for reading, continuing when available. Otherwise returns immediately.

Returns the number of bytes read (up to `slice.size`). Returns 0 when EOF is reached.

abstract def reopened(file_descriptor : Crystal::System::FileDescriptor) : Nil #

Hook to react on the file descriptor after it has been reopened. For example we might want to resume all pending operations to act on the new file descriptor.

abstract def shutdown(file_descriptor : Crystal::System::FileDescriptor) : Nil #

Internal shutdown of the file descriptor. Called after the `IO::FileDescriptor` has been marked closed but before calling `#close` to actually close the system fd or handle.

Implementations shall resume all pending waiters and let them fail because the IO has been closed.

abstract def wait_readable(file_descriptor : Crystal::System::FileDescriptor) : Nil #

Blocks the current fiber until the file descriptor is ready for read.

abstract def wait_writable(file_descriptor : Crystal::System::FileDescriptor) : Nil #

Blocks the current fiber until the file descriptor is ready for write.

abstract def write(file_descriptor : Crystal::System::FileDescriptor, slice : Bytes) : Int32 #

Writes at least one byte from slice to the file descriptor.

Blocks the current fiber if the file descriptor isn't ready for writing, continuing when ready. Otherwise returns immediately.

Returns the number of bytes written (up to `slice.size`).