Class: Sappho::Socket::SafeSocket
- Inherits:
-
Object
- Object
- Sappho::Socket::SafeSocket
- Defined in:
- lib/sappho-socket/safe_socket.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attach(socket) ⇒ Object
- #close ⇒ Object
-
#initialize(timeout = 10, socket = ConnectedSocket.new) ⇒ SafeSocket
constructor
A new instance of SafeSocket.
- #open(host, port) ⇒ Object
- #open? ⇒ Boolean
- #read(bytesNeeded) ⇒ Object
- #setTimeout(timeout) ⇒ Object
- #settle(seconds) ⇒ Object
- #write(str) ⇒ Object
Constructor Details
#initialize(timeout = 10, socket = ConnectedSocket.new) ⇒ SafeSocket
Returns a new instance of SafeSocket.
20 21 22 23 24 |
# File 'lib/sappho-socket/safe_socket.rb', line 20 def initialize timeout = 10, socket = ConnectedSocket.new @socket = socket @open = false @timeout = timeout end |
Class Method Details
.mock(session, timeout = 10) ⇒ Object
15 16 17 18 |
# File 'lib/sappho-socket/safe_socket.rb', line 15 def SafeSocket.mock session, timeout = 10 MockSocket.session session SafeSocket.new timeout, MockSocket.new end |
Instance Method Details
#attach(socket) ⇒ Object
26 27 28 29 |
# File 'lib/sappho-socket/safe_socket.rb', line 26 def attach socket @socket.attach socket @open = true end |
#close ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sappho-socket/safe_socket.rb', line 60 def close actuallyClosed = false begin timeout @timeout do if @open @socket.close actuallyClosed = true end end rescue end @open = false actuallyClosed end |
#open(host, port) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/sappho-socket/safe_socket.rb', line 31 def open host, port timeout @timeout do @socket.open host, port @open = true end end |
#open? ⇒ Boolean
75 76 77 |
# File 'lib/sappho-socket/safe_socket.rb', line 75 def open? @open end |
#read(bytesNeeded) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/sappho-socket/safe_socket.rb', line 42 def read bytesNeeded check timeout @timeout do @socket.read bytesNeeded end end |
#setTimeout(timeout) ⇒ Object
38 39 40 |
# File 'lib/sappho-socket/safe_socket.rb', line 38 def setTimeout timeout @timeout = timeout end |
#settle(seconds) ⇒ Object
56 57 58 |
# File 'lib/sappho-socket/safe_socket.rb', line 56 def settle seconds @socket.settle seconds end |
#write(str) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/sappho-socket/safe_socket.rb', line 49 def write str check timeout @timeout do @socket.write str end end |