class

OpenSSLStatic::BlockingEventLoop

Inherits Crystal::EventLoop < Crystal::EventLoop::Socket < Crystal::EventLoop::FileDescriptor < Reference < Object

Constructors

instance

Instance methods

accept(socket : ::Socket) : Tuple(::Socket::Handle, Bool) | Nil

Accepts an incoming TCP connection on the socket.

Blocks the current fiber if no connection is waiting, continuing when one becomes available. Otherwise returns immediately.

Returns a handle to the socket for the new connection.

Source

FiberEvent#add (sleep/select timeouts) — no timers on a blocking loop: the thread waits inside the syscall itself.

Source
close(socket : ::Socket) : Nil

Closes the system socket fd or handle.

Source
close(file_descriptor) : Nil
Source
connect(socket : ::Socket, address, timeout) : IO::Error | Nil
Source
create_timeout_event(fiber : Fiber) : Crystal::EventLoop::Event

Creates a timeout_event.

Source
delete_timer(event : Pointer(Crystal::EventLoop::Event)) : Nil

Event#finalize calls this on every backend; ours never creates timer events (see #create_timeout_event), so it's a no-op.

Source
interrupt

Tells a blocking run loop to no longer wait for events to activate. It may for example enqueue a NOOP event with an immediate (or past) timeout. Having activated an event, the loop shall return, allowing the blocked thread to continue.

Should be a NOOP when the loop isn't running or is running in a nonblocking mode.

NOTE: we assume that multiple threads won't run the event loop at the same time in parallel, but this assumption may change in the future!

Source
interrupt?

Same as #interrupt but returns true if a running event loop has likely been interrupted, and false otherwise.

Source
lock?

Scheduler bookkeeping — unreachable for the same reason as #run.

Source
open(path : String, flags : Int32, permissions : File::Permissions, blocking : Bool | Nil) : Errno | Tuple(Int32, Bool) | 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, slice, offset) : Int32
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
read(socket : ::Socket, slice : Bytes) : Int32

Reads at least one byte from the socket 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 the socket is closed and no data available.

Use #receive_from for capturing the source address of a message.

Source
receive_from(socket : ::Socket, slice : Bytes) : Tuple(Int32, ::Socket::Address)

Receives at least one byte from the socket into slice, capturing the source address.

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

Returns a tuple containing the number of bytes received (up to slice.size) and the source address.

Source
recvmsg(socket : ::Socket, msg : Pointer(LibC::Msghdr), flags : Int32) : Int32

kTLS path (OpenSSL::SSL::Socket with TLS 1.3 kernel offload): plain blocking recvmsg/sendmsg on the socket fd.

Source
reopened(file_descriptor) : Nil
Source
run(queue, blocking) : Nil

The scheduler entry point — never called: this loop is only handed out to scheduler-less (raw) threads, no one ever runs it.

Source
run(blocking : Bool) : Bool

Runs the loop.

Returns immediately if events are activable. Set blocking to false to return immediately if there are no activable events; set it to true to wait for activable events, which will block the current thread until then.

Returns true on normal returns (e.g. has activated events, has pending events but blocking was false) and false when there are no registered events.

Source
send_to(socket : ::Socket, slice : Bytes, address) : Int32
Source
sendfile(socket : ::Socket, fd, offset, count, flags) : Int64 | Errno | WinError
Source
sendmsg(socket : ::Socket, msg : Pointer(LibC::Msghdr), flags : Int32) : Int32
Source
shutdown(socket : ::Socket) : Nil

Internal shutdown of the socket. Called after the Socket has been marked closed but before calling #close to actually close the system socket fd or handle.

Implementations shall resume all pending waiters and let them fail because the IO has been closed. They don't have to call the shutdown syscall.

Source
shutdown(file_descriptor) : Nil
Source
sleep(duration : Time::Span) : Nil

A real sleep for raw threads: nanosleep (thread-safe, no alarm), not a fiber park — there is no fiber here.

Source
socket(family : ::Socket::Family, type : ::Socket::Type, protocol : ::Socket::Protocol, blocking : Bool | Nil) : Tuple(Int32, Bool)

Creates a new socket file descriptor or handle and returns it, along with whether the blocking flag has been set.

Source
socketpair(type : ::Socket::Type, protocol : ::Socket::Protocol) : Tuple(Tuple(Int32, Int32), Bool)

Creates a pair of UNIX socket file descriptors or handles and returns them, along with whether the blocking mode has been set.

Source
wait_readable(socket : ::Socket) : Nil

Blocks the current fiber until the socket is ready for read.

Source
wait_readable(file_descriptor) : Nil
Source
wait_writable(socket : ::Socket) : Nil

Blocks the current fiber until the socket is ready for write.

Source
wait_writable(file_descriptor) : Nil
Source
write(socket : ::Socket, slice : Bytes) : Int32

Writes at least one byte from slice to the socket.

Blocks the current fiber if the socket is not ready for writing, continuing when ready. Otherwise returns immediately.

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

Use #send_to for sending a message to a specific target address.

Source
write(file_descriptor, slice) : Int32
Source