perennial 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
data/lib/perennial.rb
CHANGED
@@ -49,15 +49,18 @@ class Perennial::Protocols::PureRuby::JSONTransport
|
|
49
49
|
"payload" => payload,
|
50
50
|
"sent-at" => Time.now
|
51
51
|
}.merge(callback_options(callback))) + SEPERATOR
|
52
|
-
with_socket
|
52
|
+
with_socket do |s|
|
53
|
+
raise NoConnection, "no connection the server at #{@host}:#{@port}" if s.nil?
|
54
|
+
s.write(message)
|
55
|
+
end
|
53
56
|
end
|
54
57
|
|
55
|
-
def read_message
|
58
|
+
def read_message(timeout = nil)
|
56
59
|
with_socket do |s|
|
57
60
|
raise NoConnection, "no connection the server at #{@host}:#{@port}" if s.nil?
|
58
61
|
message = nil
|
59
62
|
begin
|
60
|
-
Perennial::TimerImplementation.timeout(timeout) do
|
63
|
+
Perennial::TimerImplementation.timeout(timeout || @timeout) do
|
61
64
|
message = JSON.parse(s.gets.strip)
|
62
65
|
end
|
63
66
|
rescue Timeout::Error
|
@@ -118,7 +121,6 @@ class Perennial::Protocols::PureRuby::JSONTransport
|
|
118
121
|
@socket.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
|
119
122
|
@retry = nil
|
120
123
|
rescue SocketError, SystemCallError, IOError, Timeout::Error => err
|
121
|
-
# TODO: Raise a connection error here
|
122
124
|
dead!
|
123
125
|
end
|
124
126
|
@socket
|