class GxG::Networking::ZMQ::ZmqAdapter
Public Instance Methods
close()
click to toggle source
# File lib/gxg/gxg_zmq.rb, line 101 def close() if @open == true @connector.socket.close @open = false true else false end end
context()
click to toggle source
# File lib/gxg/gxg_zmq.rb, line 111 def context() if @open == true @connector.context() end end
identity()
click to toggle source
# File lib/gxg/gxg_zmq.rb, line 123 def identity() if @open == true @connector.socket.identity end end
listen(&block)
click to toggle source
# File lib/gxg/gxg_zmq.rb, line 129 def listen(&block) if @open == true @connector.listen(&block) end end
open?()
click to toggle source
# File lib/gxg/gxg_zmq.rb, line 97 def open?() @open end
receive(**options, &block)
click to toggle source
# File lib/gxg/gxg_zmq.rb, line 135 def receive(**options, &block) if @open == true @connector.receive(options, &block) end end
send(message="", **options)
click to toggle source
# File lib/gxg/gxg_zmq.rb, line 141 def send(message="", **options) if @open == true @connector.send(message.to_s,options) end end
socket()
click to toggle source
# File lib/gxg/gxg_zmq.rb, line 117 def socket() if @open == true @connector.socket() end end
vetted_parameters(params={})
click to toggle source
Proposed: {:bind/connect => <URI>, :context => <Context>, :encode => <Proc>, :decode => <Proc>}
mode (:bind, :connect) — a mode for the socket.
Options Hash:
context (ZMQ::Context) — a context to use for this socket (one will be created if not provided). encode (lambda) — how to encode messages. decode (lambda) — how to decode messages. transport (Symbol) — default: :tcp — transport for transport. address (String) — default: '127.0.0.1' — address for endpoint. port (Fixnum) — default: 5555 — port for endpoint.
# File lib/gxg/gxg_zmq.rb, line 47 def vetted_parameters(params={}) unless params.is_a?(::Hash) raise ArgumentError, "You MUST provide a Hash as parameters." end if params[:bind] # bind mode = :bind else # connect mode = :connect end options = {} if params[:context].is_a?(::ZMQ::Context) options[:context] = params[:context] end uri = params[(mode)].clone unless uri.port uri.port = 5555 end options[:port] = uri.port unless uri.is_a?(::URI::Generic) raise ArgumentError, "You MUST provide a valid URI to bind or connect to." end if ::GxG::Networking::ZMQ::zmq_supported_protocols().include?(uri.scheme()) if mode == :bind if ["tcp", "tcp4", "tcp6", "udp", "udp4", "udp6"].include?(uri.scheme()) uri.resolve_host() if ::GxG::SYSTEM.network_port_used?(::Addrinfo::parse(uri)) raise Errno::EADDRINUSE, "Address and port already in use: #{uri.to_s}" end end end else raise Exception, "Unsupported networking protocol: #{uri.scheme().inspect}" end options[:transport] = uri.scheme.to_s.to_sym options[:address] = uri.hostname if ["tcp", "tcp4", "tcp6", "udp", "udp4", "udp6"].include?(uri.scheme()) options[:port] = (uri.port || 5555) end options[:transport] = uri.scheme.to_s.to_sym if params[:encode].respond_to?(:call) options[:encode] = params[:encode] end if params[:decode].respond_to?(:call) options[:decode] = params[:decode] end {:mode => mode, :options => options} end