Class: Celluloid::ZMQ::Socket

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

Direct Known Subclasses

DealerSocket, PubSocket, PullSocket, PushSocket, RepSocket, ReqSocket, RouterSocket, SubSocket, XPubSocket

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Socket) initialize(type)

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

- (Object) linger

Returns the value of attribute linger



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

def linger
  @linger
end

Instance Method Details

- (Object) bind(addr)

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

- (Object) close

Close the socket



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

def close
  @socket.close
end

- (Object) connect(addr)

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

- (Object) get(option)



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

- (Object) identity



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

def identity
  @socket.identity
end

- (Object) identity=(value)



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

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

- (Object) set(option, value, length = nil)



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