Class: Flatware::Context
- Inherits:
-
Object
- Object
- Flatware::Context
- Defined in:
- lib/flatware/socket.rb
Instance Attribute Summary collapse
-
#c ⇒ Object
readonly
Returns the value of attribute c.
-
#sockets ⇒ Object
readonly
Returns the value of attribute sockets.
Instance Method Summary collapse
- #close(force: false) ⇒ Object
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #socket(zmq_type, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
60 61 62 63 |
# File 'lib/flatware/socket.rb', line 60 def initialize @c = ZMQ::Context.new @sockets = [] end |
Instance Attribute Details
#c ⇒ Object (readonly)
Returns the value of attribute c.
58 59 60 |
# File 'lib/flatware/socket.rb', line 58 def c @c end |
#sockets ⇒ Object (readonly)
Returns the value of attribute sockets.
58 59 60 |
# File 'lib/flatware/socket.rb', line 58 def sockets @sockets end |
Instance Method Details
#close(force: false) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/flatware/socket.rb', line 77 def close(force: false) sockets.each do |socket| socket.setsockopt ZMQ::LINGER, 0 end if force sockets.each(&:close) Flatware::socket_error unless LibZMQ.zmq_term(c.context) == 0 Flatware.log "terminated context" end |
#socket(zmq_type, options = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/flatware/socket.rb', line 65 def socket(zmq_type, ={}) Socket.new(c.socket(zmq_type)).tap do |socket| sockets.push socket if port = [:connect] socket.connect port end if port = [:bind] socket.bind port end end end |