Module: CZTop::Socket::Writable

Includes:
FdWait
Included in:
DEALER, PAIR, PUB, PUSH, REP, REQ, ROUTER, STREAM, XPUB, XSUB
Defined in:
lib/cztop/socket/writable.rb

Overview

Write 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

#send(message) ⇒ self Also known as: <<

Sends a message.

Parameters:

  • message (String, Array<String>)

    the message to send

Returns:

  • (self)

Raises:



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

def send(message)
  parts = message.is_a?(Array) ? message : [message]
  raise ArgumentError, 'message has no parts' if parts.empty?

  # Fast path: nonblock send (no GVL release)
  return self if send_nonblock(parts)

  # Slow path: FD poll → blocking send
  wait_writable

  zmsg = CZMQ::FFI::Zmsg.new
  parts.each do |part|
    rc = zmsg.add_buffer(part.to_s)
    HasFFIDelegate.raise_zmq_err unless rc.zero?
  end

  rc = CZMQ::FFI::Zmsg.send(zmsg, self)
  return self if rc.zero?

  HasFFIDelegate.raise_zmq_err
rescue Errno::EAGAIN
  raise IO::EAGAINWaitWritable
end

#wait_writable(timeout = write_timeout) ⇒ true

Waits for socket to become writable.

Parameters:

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

    timeout in seconds

Returns:

  • (true)

    if writable within timeout

Raises:

  • (IO::TimeoutError)

    if timeout has been reached



50
51
52
# File 'lib/cztop/socket/writable.rb', line 50

def wait_writable(timeout = write_timeout)
  wait_for_socket_state(:writable?, timeout)
end