Class: Celluloid::ZMQ::Socket

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/celluloid/zmq/socket.rb,
lib/celluloid/zmq/socket/types.rb,
lib/celluloid/zmq/socket/readable.rb,
lib/celluloid/zmq/socket/writable.rb

Direct Known Subclasses

Dealer, Pub, Pull, Push, Rep, Req, Router, Sub, XPub

Defined Under Namespace

Modules: Readable, Writable Classes: Dealer, Pub, Pull, Push, Rep, Req, Router, Sub, XPub

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Socket

Create a new socket



7
8
9
10
# File 'lib/celluloid/zmq/socket.rb', line 7

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.



11
12
13
# File 'lib/celluloid/zmq/socket.rb', line 11

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/



60
61
62
63
64
# File 'lib/celluloid/zmq/socket.rb', line 60

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

#closeObject

Close the socket



67
68
69
# File 'lib/celluloid/zmq/socket.rb', line 67

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/



15
16
17
18
19
20
# File 'lib/celluloid/zmq/socket.rb', line 15

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

#get(option) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/celluloid/zmq/socket.rb', line 48

def get(option)
  option_value = []

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

  option_value[0]
end

#identityObject



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

def identity
  # de @socket.identity
  get(::ZMQ::IDENTITY)
end

#identity=(value) ⇒ Object



30
31
32
33
34
35
# File 'lib/celluloid/zmq/socket.rb', line 30

def identity=(value)
  unless result_ok? @socket.setsockopt(::ZMQ::IDENTITY, "#{value}")
    fail IOError, "couldn't set identity: #{::ZMQ::Util.error_string}"
  end
  # de @socket.identity = value
end

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



42
43
44
45
46
# File 'lib/celluloid/zmq/socket.rb', line 42

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