Class: IRuby::SessionAdapter::FfirzmqAdapter
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseAdapter
available?, #close_socket, #initialize, #make_pub_socket, #make_rep_socket, #make_router_socket, #name
Class Method Details
.load_requirements ⇒ Object
4
5
6
|
# File 'lib/iruby/session_adapter/ffirzmq_adapter.rb', line 4
def self.load_requirements
require 'ffi-rzmq'
end
|
Instance Method Details
#close ⇒ Object
44
45
46
47
|
# File 'lib/iruby/session_adapter/ffirzmq_adapter.rb', line 44
def close
@zmq_context&.terminate
@zmq_context = nil
end
|
#heartbeat_loop(sock) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/iruby/session_adapter/ffirzmq_adapter.rb', line 28
def heartbeat_loop(sock)
rc = LibZMQ.zmq_proxy(sock.socket, sock.socket, nil)
errno = ZMQ::Util.errno
return if rc == -1 && (zmq_errno?(:ETERM, errno) || zmq_errno?(:EINTR, errno))
ZMQ::Util.error_check('zmq_proxy', rc)
end
|
#recv(sock) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/iruby/session_adapter/ffirzmq_adapter.rb', line 14
def recv(sock)
msg = []
while msg.empty? || sock.more_parts?
begin
frame = ''
rc = sock.recv_string(frame)
ZMQ::Util.error_check('zmq_msg_recv', rc)
msg << frame
rescue
end
end
msg
end
|
#send(sock, data) ⇒ Object
8
9
10
11
12
|
# File 'lib/iruby/session_adapter/ffirzmq_adapter.rb', line 8
def send(sock, data)
data.each_with_index do |part, i|
sock.send_string(part, i == data.size - 1 ? 0 : ZMQ::SNDMORE)
end
end
|
#shutdown_heartbeat(sock) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/iruby/session_adapter/ffirzmq_adapter.rb', line 37
def shutdown_heartbeat(sock)
if @zmq_context&.context && LibZMQ.respond_to?(:zmq_ctx_shutdown)
LibZMQ.zmq_ctx_shutdown(@zmq_context.context)
end
close_socket(sock)
end
|