Class: ZMachine::ZMQChannel
- Inherits:
-
Channel
- Object
- Channel
- ZMachine::ZMQChannel
show all
- Extended by:
- Forwardable
- Defined in:
- lib/zmachine/zmq_channel.rb
Instance Attribute Summary
Attributes inherited from Channel
#raw, #socket
Instance Method Summary
collapse
Methods inherited from Channel
#can_send?, #close, #send_data, #write_outbound_data
Constructor Details
Returns a new instance of ZMQChannel.
12
13
14
15
|
# File 'lib/zmachine/zmq_channel.rb', line 12
def initialize
super
@raw = true
end
|
Instance Method Details
#accept ⇒ Object
33
34
35
36
|
# File 'lib/zmachine/zmq_channel.rb', line 33
def accept
ZMachine.logger.debug("zmachine:zmq_channel:#{__method__}", channel: self) if ZMachine.debug
self
end
|
#bind(address, type) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/zmachine/zmq_channel.rb', line 21
def bind(address, type)
ZMachine.logger.debug("zmachine:zmq_channel:#{__method__}", channel: self) if ZMachine.debug
@bound = true
@connected = true
@socket = ZContext.create_socket(type)
@socket.bind(address)
end
|
#bound? ⇒ Boolean
29
30
31
|
# File 'lib/zmachine/zmq_channel.rb', line 29
def bound?
@bound
end
|
#can_recv? ⇒ Boolean
see comment in ConnectionManager#process
84
85
86
|
# File 'lib/zmachine/zmq_channel.rb', line 84
def can_recv?
@socket.events & ZMQ::Poller::POLLIN == ZMQ::Poller::POLLIN
end
|
#close! ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/zmachine/zmq_channel.rb', line 67
def close!
ZMachine.logger.debug("zmachine:zmq_channel:#{__method__}", channel: self) if ZMachine.debug
@closed = true
@connected = false
@bound = false
ZContext.destroy_socket(@socket)
end
|
#closed? ⇒ Boolean
75
76
77
|
# File 'lib/zmachine/zmq_channel.rb', line 75
def closed?
@closed
end
|
#connect(address, type) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/zmachine/zmq_channel.rb', line 38
def connect(address, type)
ZMachine.logger.debug("zmachine:zmq_channel:#{__method__}", channel: self) if ZMachine.debug
@connection_pending = true
@socket = ZContext.create_socket(type)
@socket.connect(address)
end
|
#connected? ⇒ Boolean
55
56
57
|
# File 'lib/zmachine/zmq_channel.rb', line 55
def connected?
@connected
end
|
#connection_pending? ⇒ Boolean
45
46
47
|
# File 'lib/zmachine/zmq_channel.rb', line 45
def connection_pending?
@connection_pending
end
|
#finish_connecting ⇒ Object
49
50
51
52
53
|
# File 'lib/zmachine/zmq_channel.rb', line 49
def finish_connecting
ZMachine.logger.debug("zmachine:zmq_channel:#{__method__}", channel: self) if ZMachine.debug
return unless connection_pending?
@connected = true
end
|
#peer ⇒ Object
79
80
81
|
# File 'lib/zmachine/zmq_channel.rb', line 79
def peer
raise RuntimeError.new("ZMQChannel has no peer")
end
|
#read_inbound_data ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/zmachine/zmq_channel.rb', line 59
def read_inbound_data
ZMachine.logger.debug("zmachine:zmq_channel:#{__method__}", channel: self) if ZMachine.debug
return nil unless can_recv?
data = ZMsg.recv_msg(@socket)
data = String.from_java_bytes(data.first.data) unless @raw
data
end
|
#selectable_fd ⇒ Object
17
18
19
|
# File 'lib/zmachine/zmq_channel.rb', line 17
def selectable_fd
@socket.fd
end
|