module

Crystal::EventLoop::FileDescriptor

Instance methods

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

Closes the system fd or handle.

Source
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.

Source
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.

Source
pread(file_descriptor : Crystal::System::FileDescriptor, slice : Bytes, offset : Int64) : Int32

Identical to #read but takes an offset into the file to read at, instead of the current position. Doesn't affect the current position.

Source
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.

Source
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.

Source
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.

Source
wait_readable(file_descriptor : Crystal::System::FileDescriptor) : Nil

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

Source
wait_writable(file_descriptor : Crystal::System::FileDescriptor) : Nil

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

Source
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).

Source