Class: ZSS::Socket
- Inherits:
-
Object
- Object
- ZSS::Socket
- Defined in:
- lib/zss/socket.rb
Defined Under Namespace
Classes: Error, TimeoutError
Instance Attribute Summary collapse
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
-
#socket_address ⇒ Object
readonly
Returns the value of attribute socket_address.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
- #call(request, call_timeout = nil) ⇒ Object
-
#initialize(config) ⇒ Socket
constructor
A new instance of Socket.
Constructor Details
#initialize(config) ⇒ Socket
Returns a new instance of Socket.
11 12 13 14 15 |
# File 'lib/zss/socket.rb', line 11 def initialize config @identity = config.identity @timeout = config.timeout || 1000 @socket_address = config.socket_address end |
Instance Attribute Details
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
9 10 11 |
# File 'lib/zss/socket.rb', line 9 def identity @identity end |
#socket_address ⇒ Object (readonly)
Returns the value of attribute socket_address.
9 10 11 |
# File 'lib/zss/socket.rb', line 9 def socket_address @socket_address end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/zss/socket.rb', line 9 def timeout @timeout end |
Instance Method Details
#call(request, call_timeout = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zss/socket.rb', line 17 def call request, call_timeout = nil fail Socket::Error, 'invalid request' unless request response = nil t = (call_timeout || timeout) / 1000.0 context do |ctx| socket ctx do |sock| begin ::Timeout.timeout t do sock, request response = (sock) end rescue ::Timeout::Error raise ZSS::Socket::TimeoutError, "call timeout after #{t}s" end end end response end |