Class: Flatware::Socket
- Inherits:
-
Object
- Object
- Flatware::Socket
- Defined in:
- lib/flatware/socket.rb
Defined Under Namespace
Classes: Monitor
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #bind(port) ⇒ Object
- #close ⇒ Object
- #connect(port) ⇒ Object
- #error ⇒ Object
-
#initialize(socket) ⇒ Socket
constructor
A new instance of Socket.
- #monitor ⇒ Object
- #name ⇒ Object
- #recv(block: true, marshal: true) ⇒ Object
- #send(message) ⇒ Object
- #setsockopt(*args) ⇒ Object
Constructor Details
#initialize(socket) ⇒ Socket
90 91 92 |
# File 'lib/flatware/socket.rb', line 90 def initialize(socket) @socket = socket end |
Instance Attribute Details
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
88 89 90 |
# File 'lib/flatware/socket.rb', line 88 def socket @socket end |
Instance Method Details
#bind(port) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/flatware/socket.rb', line 145 def bind(port) @type = 'bound' @port = port error unless socket.bind(port) == 0 Flatware.log "bind #@port" end |
#close ⇒ Object
152 153 154 155 |
# File 'lib/flatware/socket.rb', line 152 def close error unless socket.close == 0 Flatware.log "close #@type #@port" end |
#connect(port) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/flatware/socket.rb', line 109 def connect(port) @type = 'connected' @port = port error unless socket.connect(port) == 0 Flatware.log "connect #@port" end |
#error ⇒ Object
157 158 159 |
# File 'lib/flatware/socket.rb', line 157 def error Flatware::socket_error name end |
#monitor ⇒ Object
116 117 118 119 120 |
# File 'lib/flatware/socket.rb', line 116 def monitor name = "inproc://monitor#{SecureRandom.hex(10)}" LibZMQ.zmq_socket_monitor(socket.socket, name, ZMQ::EVENT_ALL) Monitor.new(name) end |
#name ⇒ Object
98 99 100 |
# File 'lib/flatware/socket.rb', line 98 def name socket.name end |
#recv(block: true, marshal: true) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/flatware/socket.rb', line 161 def recv(block: true, marshal: true) = '' if block result = socket.recv_string() error if result == -1 else socket.recv_string(, ZMQ::NOBLOCK) end if != '' and marshal = Marshal.load() end Flatware.log "#@type #@port recv #{}" end |
#send(message) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/flatware/socket.rb', line 102 def send() result = socket.send_string(Marshal.dump()) error if result == -1 Flatware.log "#@type #@port send #{}" end |
#setsockopt(*args) ⇒ Object
94 95 96 |
# File 'lib/flatware/socket.rb', line 94 def setsockopt(*args) socket.setsockopt(*args) end |