Class: CZTop::Socket
- Inherits:
-
Object
- Object
- CZTop::Socket
- Extended by:
- HasFFIDelegate::ClassMethods
- Includes:
- CZMQ::FFI, HasFFIDelegate, ZsockOptions
- Defined in:
- lib/cztop/socket.rb,
lib/cztop/socket/pub.rb,
lib/cztop/socket/rep.rb,
lib/cztop/socket/req.rb,
lib/cztop/socket/sub.rb,
lib/cztop/socket/pair.rb,
lib/cztop/socket/pull.rb,
lib/cztop/socket/push.rb,
lib/cztop/socket/xpub.rb,
lib/cztop/socket/xsub.rb,
lib/cztop/socket/types.rb,
lib/cztop/socket/dealer.rb,
lib/cztop/socket/router.rb,
lib/cztop/socket/stream.rb,
lib/cztop/socket/fd_wait.rb,
lib/cztop/socket/readable.rb,
lib/cztop/socket/writable.rb
Overview
Represents a CZMQ::FFI::Zsock.
Defined Under Namespace
Modules: FdWait, Readable, Types, Writable Classes: DEALER, PAIR, PUB, PULL, PUSH, REP, REQ, ROUTER, STREAM, SUB, XPUB, XSUB
Constant Summary collapse
- TypeNames =
All the available type codes, mapped to their Symbol equivalent.
Types.constants.to_h do |name| i = Types.const_get(name) [i, name] end.freeze
Constants included from CZMQ::FFI
CZMQ::FFI::CZMQ_VERSION, CZMQ::FFI::ZFRAME_DONTWAIT, CZMQ::FFI::ZFRAME_MORE, CZMQ::FFI::ZMONITOR_FN, CZMQ::FFI::ZMQ_VERSION
Constants included from ZsockOptions
ZsockOptions::POLLIN, ZsockOptions::POLLOUT
Instance Attribute Summary collapse
- #last_tcp_port ⇒ Integer? readonly
Attributes included from HasFFIDelegate
Class Method Summary collapse
-
.bind(endpoint, **opts) ⇒ Socket
Creates a new socket and binds it to the given endpoint.
-
.connect(endpoint, **opts) ⇒ Socket
Creates a new socket and connects it to the given endpoint.
Instance Method Summary collapse
-
#bind(endpoint) ⇒ void
Binds to an endpoint.
-
#close ⇒ void
Closes and destroys the native socket.
-
#connect(endpoint) ⇒ void
Connects to an endpoint.
-
#disconnect(endpoint) ⇒ void
Disconnects from an endpoint.
-
#initialize(endpoints = nil, curve: nil, linger: 0) ⇒ Socket
constructor
A new instance of Socket.
-
#inspect ⇒ String
Inspects this Socket.
- #last_endpoint ⇒ String?
-
#set_unbounded ⇒ Object
Set socket to use unbounded pipes (HWM=0); use this in cases when you are totally certain the message volume can fit in memory.
-
#unbind(endpoint) ⇒ void
Unbinds from an endpoint.
Methods included from HasFFIDelegate::ClassMethods
ffi_delegate, from_ffi_delegate
Methods included from ZsockOptions
#conflate=, #conflate?, #fd, #heartbeat_ivl, #heartbeat_ivl=, #heartbeat_timeout, #heartbeat_timeout=, #heartbeat_ttl, #heartbeat_ttl=, #identity, #identity=, #immediate=, #immediate?, #ipv6=, #ipv6?, #linger, #linger=, #max_msg_size, #max_msg_size=, #rcvhwm, #rcvhwm=, #readable?, #reconnect_ivl, #reconnect_ivl=, #reconnect_ivl_max, #reconnect_ivl_max=, #recv_timeout, #recv_timeout=, #router_mandatory=, #router_mandatory?, #send_timeout, #send_timeout=, #sndhwm, #sndhwm=, #tcp_keepalive, #tcp_keepalive=, #tcp_keepalive_cnt, #tcp_keepalive_cnt=, #tcp_keepalive_idle, #tcp_keepalive_idle=, #tcp_keepalive_intvl, #tcp_keepalive_intvl=, #to_io, #tos, #tos=, #writable?
Methods included from HasFFIDelegate
#attach_ffi_delegate, #from_ffi_delegate, raise_zmq_err, #to_ptr
Constructor Details
#initialize(endpoints = nil, curve: nil, linger: 0) ⇒ Socket
Returns a new instance of Socket.
36 |
# File 'lib/cztop/socket.rb', line 36 def initialize(endpoints = nil, curve: nil, linger: 0); end |
Instance Attribute Details
#last_tcp_port ⇒ Integer? (readonly)
81 82 83 |
# File 'lib/cztop/socket.rb', line 81 def last_tcp_port @last_tcp_port end |
Class Method Details
.bind(endpoint, **opts) ⇒ Socket
Creates a new socket and binds it to the given endpoint.
20 21 22 |
# File 'lib/cztop/socket.rb', line 20 def self.bind(endpoint, **opts) new(nil, **opts).tap { |s| s.bind(endpoint) } end |
.connect(endpoint, **opts) ⇒ Socket
Creates a new socket and connects it to the given endpoint.
31 32 33 |
# File 'lib/cztop/socket.rb', line 31 def self.connect(endpoint, **opts) new(nil, **opts).tap { |s| s.connect(endpoint) } end |
Instance Method Details
#bind(endpoint) ⇒ void
When binding to an automatically selected TCP port, this will set #last_tcp_port.
This method returns an undefined value.
Binds to an endpoint.
90 91 92 93 94 |
# File 'lib/cztop/socket.rb', line 90 def bind(endpoint) rc = ffi_delegate.bind('%s', :string, endpoint) raise_zmq_err(format('unable to bind to %p', endpoint)) if rc == -1 @last_tcp_port = rc if rc.positive? end |
#close ⇒ void
Don't try to use it anymore afterwards.
This method returns an undefined value.
Closes and destroys the native socket.
73 74 75 76 |
# File 'lib/cztop/socket.rb', line 73 def close ffi_delegate.destroy nil end |
#connect(endpoint) ⇒ void
This method returns an undefined value.
Connects to an endpoint.
52 53 54 55 |
# File 'lib/cztop/socket.rb', line 52 def connect(endpoint) rc = ffi_delegate.connect('%s', :string, endpoint) raise ArgumentError, format('incorrect endpoint: %p', endpoint) if rc == -1 end |
#disconnect(endpoint) ⇒ void
This method returns an undefined value.
Disconnects from an endpoint.
63 64 65 66 |
# File 'lib/cztop/socket.rb', line 63 def disconnect(endpoint) rc = ffi_delegate.disconnect('%s', :string, endpoint) raise ArgumentError, format('incorrect endpoint: %p', endpoint) if rc == -1 end |
#inspect ⇒ String
Inspects this CZTop::Socket.
120 121 122 123 124 |
# File 'lib/cztop/socket.rb', line 120 def inspect format('#<%s:0x%x last_endpoint=%p>', self.class, to_ptr.address, last_endpoint) rescue Zsock::DestroyedError format('#<%s: invalid>', self.class) end |
#last_endpoint ⇒ String?
42 43 44 |
# File 'lib/cztop/socket.rb', line 42 def last_endpoint ffi_delegate.endpoint end |
#set_unbounded ⇒ Object
Set socket to use unbounded pipes (HWM=0); use this in cases when you are totally certain the message volume can fit in memory.
111 112 113 114 |
# File 'lib/cztop/socket.rb', line 111 def set_unbounded ::CZMQ::FFI::Zsock.set_unbounded(ffi_delegate) nil end |
#unbind(endpoint) ⇒ void
This method returns an undefined value.
Unbinds from an endpoint.
102 103 104 105 |
# File 'lib/cztop/socket.rb', line 102 def unbind(endpoint) rc = ffi_delegate.unbind('%s', :string, endpoint) raise ArgumentError, format('incorrect endpoint: %p', endpoint) if rc == -1 end |