Class: Specjour::Connection
- Inherits:
-
Object
- Object
- Specjour::Connection
show all
- Extended by:
- Forwardable
- Includes:
- Protocol
- Defined in:
- lib/specjour/connection.rb
Constant Summary
Constants included
from Protocol
Protocol::TERMINATOR, Protocol::TERMINATOR_REGEXP
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Protocol
#dump_object, #load_object
Constructor Details
Returns a new instance of Connection.
18
19
20
|
# File 'lib/specjour/connection.rb', line 18
def initialize(uri)
@uri = uri
end
|
Instance Attribute Details
#socket ⇒ Object
26
27
28
|
# File 'lib/specjour/connection.rb', line 26
def socket
@socket ||= connect
end
|
#uri ⇒ Object
Returns the value of attribute uri.
6
7
8
|
# File 'lib/specjour/connection.rb', line 6
def uri
@uri
end
|
Class Method Details
.wrap(established_connection) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/specjour/connection.rb', line 11
def self.wrap(established_connection)
host, port = established_connection.peeraddr.values_at(3,1)
connection = new URI::Generic.build(:host => host, :port => port)
connection.socket = established_connection
connection
end
|
Instance Method Details
#connect ⇒ Object
22
23
24
|
# File 'lib/specjour/connection.rb', line 22
def connect
timeout { connect_socket }
end
|
#print(arg) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/specjour/connection.rb', line 36
def print(arg)
socket.print dump_object(arg)
rescue SystemCallError => error
reconnect
retry
end
|
#puts(arg) ⇒ Object
43
44
45
|
# File 'lib/specjour/connection.rb', line 43
def puts(arg)
print(arg << "\n")
end
|
#send_message(method_name, *args) ⇒ Object
47
48
49
50
|
# File 'lib/specjour/connection.rb', line 47
def send_message(method_name, *args)
print([method_name, *args])
flush
end
|
#timeout(&block) ⇒ Object
30
31
32
33
34
|
# File 'lib/specjour/connection.rb', line 30
def timeout(&block)
Timeout.timeout(5, &block)
rescue Timeout::Error
raise Error, "Connection to dispatcher timed out"
end
|