Module: CZTop::Socket::Writable
- Includes:
- FdWait
- 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
-
#send(message) ⇒ self
(also: #<<)
Sends a message.
-
#wait_writable(timeout = write_timeout) ⇒ true
Waits for socket to become writable.
Methods included from FdWait
#wait_for_fd_signal, #wait_for_socket_state
Instance Method Details
#send(message) ⇒ self Also known as: <<
Sends a message.
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() parts = .is_a?(Array) ? : [] 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.
50 51 52 |
# File 'lib/cztop/socket/writable.rb', line 50 def wait_writable(timeout = write_timeout) wait_for_socket_state(:writable?, timeout) end |