Module: CZTop::Socket::Readable

Includes:
FdWait
Included in:
DEALER, PAIR, PULL, REP, REQ, ROUTER, STREAM, SUB, XPUB, XSUB
Defined in:
lib/cztop/socket/readable.rb

Overview

Read capability for ZMQ sockets.

Constant Summary

Constants included from FdWait

FdWait::FD_TIMEOUT, FdWait::JIFFY

Instance Method Summary collapse

Methods included from FdWait

#wait_for_fd_signal, #wait_for_socket_state

Instance Method Details

#receiveArray<String>

Receives a message.

Returns:

  • (Array<String>)

    message parts

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cztop/socket/readable.rb', line 17

def receive
  # Fast path: nonblock recv (no GVL release)
  parts = recv_nonblock
  return parts if parts

  # Slow path: FD poll → blocking recv
  wait_readable

  zmsg = CZMQ::FFI::Zmsg.recv(self)
  HasFFIDelegate.raise_zmq_err if zmsg.null?

  parts = []
  frame = zmsg.first
  while frame
    parts << frame.data.read_bytes(frame.size)
    frame = zmsg.next
  end
  parts
rescue Errno::EAGAIN
  raise IO::EAGAINWaitReadable
end

#wait_readable(timeout = read_timeout) ⇒ true

Waits for socket to become readable.

Parameters:

  • timeout (Numeric, nil) (defaults to: read_timeout)

    timeout in seconds

Returns:

  • (true)

    if readable within timeout

Raises:

  • (IO::TimeoutError)

    if timeout has been reached



45
46
47
# File 'lib/cztop/socket/readable.rb', line 45

def wait_readable(timeout = read_timeout)
  wait_for_socket_state(:readable?, timeout)
end