Class: Celluloid::ZMQ::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/zmq/sockets.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Socket

Create a new socket



5
6
7
8
# File 'lib/celluloid/zmq/sockets.rb', line 5

def initialize(type)
  @socket = Celluloid::ZMQ.context.socket ::ZMQ.const_get(type.to_s.upcase)
  @linger = 0
end

Instance Attribute Details

#lingerObject

Returns the value of attribute linger



9
10
11
# File 'lib/celluloid/zmq/sockets.rb', line 9

def linger
  @linger
end

Instance Method Details

#bind(addr) ⇒ Object

Bind to the given 0MQ address Address should be in the form: tcp://1.2.3.4:5678/



54
55
56
57
58
# File 'lib/celluloid/zmq/sockets.rb', line 54

def bind(addr)
  unless ::ZMQ::Util.resultcode_ok? @socket.bind(addr)
    raise IOError, "couldn't bind to #{addr}: #{::ZMQ::Util.error_string}"
  end
end

#closeObject

Close the socket



61
62
63
# File 'lib/celluloid/zmq/sockets.rb', line 61

def close
  @socket.close
end

#connect(addr) ⇒ Object

Connect to the given 0MQ address Address should be in the form: tcp://1.2.3.4:5678/



13
14
15
16
17
18
# File 'lib/celluloid/zmq/sockets.rb', line 13

def connect(addr)
  unless ::ZMQ::Util.resultcode_ok? @socket.connect addr
    raise IOError, "error connecting to #{addr}: #{::ZMQ::Util.error_string}"
  end
  true
end

#get(option) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/celluloid/zmq/sockets.rb', line 42

def get(option)
  option_value = []

  unless ::ZMQ::Util.resultcode_ok? @socket.getsockopt(option, option_value)
    raise IOError, "couldn't get value for option #{option}: #{::ZMQ::Util.error_string}"
  end

  option_value[0]
end

#identityObject



32
33
34
# File 'lib/celluloid/zmq/sockets.rb', line 32

def identity
  @socket.identity
end

#identity=(value) ⇒ Object



28
29
30
# File 'lib/celluloid/zmq/sockets.rb', line 28

def identity=(value)
  @socket.identity = value
end

#set(option, value, length = nil) ⇒ Object



36
37
38
39
40
# File 'lib/celluloid/zmq/sockets.rb', line 36

def set(option, value, length = nil)
  unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(option, value, length)
    raise IOError, "couldn't set value for option #{option}: #{::ZMQ::Util.error_string}"
  end
end