Class: BZMQ::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/bzmq/socket.rb

Instance Method Summary collapse

Constructor Details

#initialize(type, options = {}) ⇒ Socket

Returns a new instance of Socket.

Raises:



4
5
6
7
8
9
10
11
# File 'lib/bzmq/socket.rb', line 4

def initialize(type, options={})
  context = Context.context(options[:io_threads] || 1)
  @socket = context.socket(type)
  raise SocketError unless @socket
  error_check { @socket.setsockopt ZMQ::LINGER, options[:linger] || -1 }
  error_check { @socket.setsockopt ZMQ::RCVTIMEO, options[:timeout] || -1 }
  error_check { @socket.setsockopt ZMQ::SNDTIMEO, options[:timeout] || -1 }
end

Instance Method Details

#bind(address) ⇒ Object



13
14
15
# File 'lib/bzmq/socket.rb', line 13

def bind(address)
  @connected = error_check { @socket.bind(address) }
end

#closeObject



21
22
23
# File 'lib/bzmq/socket.rb', line 21

def close
  !(@connected = !error_check { @socket.close })
end

#connect(address) ⇒ Object



17
18
19
# File 'lib/bzmq/socket.rb', line 17

def connect(address)
  @connected = error_check { @socket.connect(address) }
end

#read(buffer = '') ⇒ Object



25
26
27
28
# File 'lib/bzmq/socket.rb', line 25

def read(buffer='')
  connected_error_check { @socket.recv_string buffer }
  buffer
end

#write(message) ⇒ Object



30
31
32
# File 'lib/bzmq/socket.rb', line 30

def write(message)
  connected_error_check { @socket.send_string message }
end