Class: CarbonMU::ReadSocket

Inherits:
CarbonIPCSocket show all
Defined in:
lib/ipc/read_socket.rb

Instance Attribute Summary

Attributes inherited from CarbonIPCSocket

#zmq_socket

Instance Method Summary collapse

Methods inherited from CarbonIPCSocket

#close, #send

Constructor Details

#initialize(port = '*') ⇒ ReadSocket

Returns a new instance of ReadSocket.


3
4
5
6
# File 'lib/ipc/read_socket.rb', line 3

def initialize(port = '*')
  @zmq_socket = Celluloid::ZMQ::PullSocket.new
  @zmq_socket.bind("tcp://127.0.0.1:#{port}")
end

Instance Method Details

#port_numberObject


12
13
14
15
16
# File 'lib/ipc/read_socket.rb', line 12

def port_number
  raw_endpoint = @zmq_socket.get(::ZMQ::LAST_ENDPOINT) || nil
  return nil if raw_endpoint.nil?
  raw_endpoint.match(/\:(\d+)/)[1].to_i
end

#readObject


8
9
10
# File 'lib/ipc/read_socket.rb', line 8

def read
  @zmq_socket.read
end