Class: Bundesstrasse::Socket

Inherits:
Object
  • Object
show all
Includes:
Errors
Defined in:
lib/bundesstrasse/socket.rb

Direct Known Subclasses

SubSocket

Instance Method Summary collapse

Methods included from Errors

#errno, #error_string

Constructor Details

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

Returns a new instance of Socket.



5
6
7
8
# File 'lib/bundesstrasse/socket.rb', line 5

def initialize(socket, options={})
  @socket = socket
  setup!(options)
end

Instance Method Details

#bind(address) ⇒ Object



10
11
12
# File 'lib/bundesstrasse/socket.rb', line 10

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

#close!Object



18
19
20
# File 'lib/bundesstrasse/socket.rb', line 18

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

#connect(address) ⇒ Object



14
15
16
# File 'lib/bundesstrasse/socket.rb', line 14

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

#connected?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/bundesstrasse/socket.rb', line 59

def connected?
  @connected
end

#more_parts?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/bundesstrasse/socket.rb', line 50

def more_parts?
  @socket.more_parts?
end

#pointerObject Also known as: socket



54
55
56
# File 'lib/bundesstrasse/socket.rb', line 54

def pointer
  @socket.socket
end

#read(buffer = '') ⇒ Object



22
23
24
25
# File 'lib/bundesstrasse/socket.rb', line 22

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

#read_multipartObject



40
41
42
43
44
# File 'lib/bundesstrasse/socket.rb', line 40

def read_multipart
  messages = []
  connected_error_check { @socket.recv_strings(messages) }
  messages
end

#read_nonblocking(buffer = '') ⇒ Object



31
32
33
34
# File 'lib/bundesstrasse/socket.rb', line 31

def read_nonblocking(buffer='')
  connected_error_check { @socket.recv_string(buffer, ZMQ::NonBlocking) }
  buffer
end

#write(message) ⇒ Object



27
28
29
# File 'lib/bundesstrasse/socket.rb', line 27

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

#write_multipart(*parts) ⇒ Object



46
47
48
# File 'lib/bundesstrasse/socket.rb', line 46

def write_multipart(*parts)
  connected_error_check { @socket.send_strings(parts) }
end

#write_nonblocking(message) ⇒ Object



36
37
38
# File 'lib/bundesstrasse/socket.rb', line 36

def write_nonblocking(message)
  connected_error_check { @socket.send_string(message, ZMQ::NonBlocking) }
end