Class: Usbmux::SafeStreamSocket
- Inherits:
-
Object
- Object
- Usbmux::SafeStreamSocket
- Defined in:
- lib/usbmux/usbmux.rb
Instance Attribute Summary collapse
-
#sock ⇒ Object
Returns the value of attribute sock.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(family, address) ⇒ SafeStreamSocket
constructor
A new instance of SafeStreamSocket.
- #receive(size) ⇒ Object
- #send(message) ⇒ Object
Constructor Details
permalink #initialize(family, address) ⇒ SafeStreamSocket
Returns a new instance of SafeStreamSocket.
12 13 14 15 |
# File 'lib/usbmux/usbmux.rb', line 12 def initialize(family, address) @sock = Socket.new(family, Socket::SOCK_STREAM) @sock.connect(address) end |
Instance Attribute Details
permalink #sock ⇒ Object
Returns the value of attribute sock.
10 11 12 |
# File 'lib/usbmux/usbmux.rb', line 10 def sock @sock end |
Instance Method Details
permalink #close ⇒ Object
[View source]
40 41 42 |
# File 'lib/usbmux/usbmux.rb', line 40 def close @sock.close end |
permalink #receive(size) ⇒ Object
[View source]
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/usbmux/usbmux.rb', line 28 def receive(size) = '' while .length < size chunk = @sock.recv(size - .length) if chunk.empty? raise MuxError.new('Socket connection broken') end = + chunk end end |
permalink #send(message) ⇒ Object
[View source]
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/usbmux/usbmux.rb', line 17 def send() total_sent = 0 while total_sent < .length sent = @sock.send([total_sent..-1], 0) if sent == 0 raise MuxError.new('Socket connection broken') end total_sent += sent end end |