class

Socket

Inherits Crystal::System::Socket < IO::Buffered < IO < Reference < Object

Instance methods

read_nonblock(slice : Bytes) : Int32 | Nil

Reads at most slice.size bytes into slice without waiting for data. Returns the number of bytes read (0 at end of stream), or nil if no data is available. Use #wait_readable to wait for data.

Source
shutdown_read_write

Shuts the connection down both ways (shutdown(2)) without closing the file descriptor, so that fibers blocked reading from or writing to the socket fail right away instead of waiting for a timeout. Errors, e.g. when the peer is already gone or the socket is closed, are ignored.

Source
wait_readable

Waits until the socket is readable. Raises IO::TimeoutError after read_timeout, and IO::Error if the socket is closed meanwhile.

Doesn't take the fd's read lock, so it doesn't serialize readers like a blocking read does: of several fibers waiting, an incoming edge wakes one.

Source