Class: Wine::Connection
- Inherits:
-
Object
- Object
- Wine::Connection
- Defined in:
- lib/wine/connection.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
5000
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(socket) ⇒ Connection
constructor
A new instance of Connection.
- #recv(timeout = DEFAULT_TIMEOUT) ⇒ Object
- #recv_nonblock ⇒ Object
- #send(message) ⇒ Object
Constructor Details
#initialize(socket) ⇒ Connection
Returns a new instance of Connection.
11 12 13 |
# File 'lib/wine/connection.rb', line 11 def initialize(socket) @socket = socket end |
Instance Attribute Details
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
9 10 11 |
# File 'lib/wine/connection.rb', line 9 def socket @socket end |
Instance Method Details
#close ⇒ Object
40 41 42 |
# File 'lib/wine/connection.rb', line 40 def close @socket.close end |
#recv(timeout = DEFAULT_TIMEOUT) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/wine/connection.rb', line 19 def recv(timeout = DEFAULT_TIMEOUT) readable = IO.select([ @socket ], nil, nil, timeout / 1000.0) return nil unless readable msg_type = @socket.recv(1, Socket::MSG_PEEK) raise ConnectionClosed unless msg_type.length == 1 Message.read(@socket) end |
#recv_nonblock ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wine/connection.rb', line 29 def recv_nonblock begin msg_type = @socket.recv_nonblock(1, Socket::MSG_PEEK) raise ConnectionClosed unless msg_type.length == 1 Message.read(@socket) rescue IO::WaitReadable nil end end |
#send(message) ⇒ Object
15 16 17 |
# File 'lib/wine/connection.rb', line 15 def send() .write(@socket) end |