Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/crystal/system/file_descriptor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ module Crystal::System::FileDescriptor
event_loop.write(self, slice)
end

private def system_wait_readable : Nil
event_loop.wait_readable(self)
end

private def system_wait_writable : Nil
event_loop.wait_writable(self)
end

private def event_loop? : Crystal::EventLoop::FileDescriptor?
Crystal::EventLoop.current?
end
Expand Down
8 changes: 8 additions & 0 deletions src/crystal/system/socket.cr
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ module Crystal::System::Socket
event_loop.write(self, slice)
end

private def system_wait_readable : Nil
event_loop.wait_readable(self)
end

private def system_wait_writable : Nil
event_loop.wait_writable(self)
end

# private def system_close

# Closes the internal handle without notifying the event loop.
Expand Down
14 changes: 14 additions & 0 deletions src/io/file_descriptor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,18 @@ class IO::FileDescriptor < IO
private def unbuffered_flush : Nil
# Nothing
end

# Blocks the current fiber until the file descriptor is ready for read.
# Raises `TimeoutError` when the configured `#read_timeout` has elapsed,
# otherwise returns normally.
def wait_readable : Nil
system_wait_readable
end

# Blocks the current fiber until the file descriptor is ready for write.
# Raises `TimeoutError` when the configured `#write_timeout` has elapsed,
# otherwise returns normally.
def wait_writable : Nil
system_wait_writable
end
end
14 changes: 14 additions & 0 deletions src/socket.cr
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,20 @@ class Socket < IO
private def unbuffered_flush : Nil
# Nothing
end

# Blocks the current fiber until the socket is ready for read. Raises
# `TimeoutError` when the configured `#read_timeout` has elapsed, otherwise
# returns normally.
def wait_readable : Nil
system_wait_readable
end

# Blocks the current fiber until the socket is ready for write. Raises
# `TimeoutError` when the configured `#write_timeout` has elapsed, otherwise
# returns normally.
def wait_writable : Nil
system_wait_writable
end
end

require "./socket/*"