Class: Miu::Socket

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSocket

Returns a new instance of Socket.



27
28
29
30
# File 'lib/miu/sockets.rb', line 27

def initialize
  @socket = Miu.context.socket ::ZMQ.const_get(socket_type)
  @linger = 0
end

Instance Attribute Details

#lingerObject

Returns the value of attribute linger.



25
26
27
# File 'lib/miu/sockets.rb', line 25

def linger
  @linger
end

#socketObject (readonly)

Returns the value of attribute socket.



24
25
26
# File 'lib/miu/sockets.rb', line 24

def socket
  @socket
end

Class Method Details

.build_address(*args) ⇒ Object



17
18
19
20
21
# File 'lib/miu/sockets.rb', line 17

def build_address(*args)
  host = args.shift
  port = args.shift
  port ? "tcp://#{host}:#{port}" : host
end

.inherited(base) ⇒ Object



8
9
10
# File 'lib/miu/sockets.rb', line 8

def inherited(base)
  base.socket_type socket_type
end

.socket_type(type = nil) ⇒ Object



12
13
14
15
# File 'lib/miu/sockets.rb', line 12

def socket_type(type = nil)
  @socket_type = type if type
  @socket_type
end

Instance Method Details

#bind(address) ⇒ Object



36
37
38
# File 'lib/miu/sockets.rb', line 36

def bind(address)
  error_wrapper { @socket.bind address }
end

#closeObject



49
50
51
# File 'lib/miu/sockets.rb', line 49

def close
  @socket.close
end

#connect(address) ⇒ Object



40
41
42
# File 'lib/miu/sockets.rb', line 40

def connect(address)
  error_wrapper { @socket.connect address }
end

#socket_typeObject



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

def socket_type
  @type ||= self.class.socket_type.to_s.upcase.to_sym
end

#to_ioObject



53
54
55
# File 'lib/miu/sockets.rb', line 53

def to_io
  @socket
end