lib/stomp.rb in stomp-1.0.2 vs lib/stomp.rb in stomp-1.0.3
- old
+ new
@@ -21,27 +21,27 @@
# Low level connection which maps commands and supports
# synchronous receives
class Connection
- def Connection.open(login = "", passcode = "", host='localhost', port=61613, reliable=FALSE)
- Connection.new login, passcode, host, port, reliable
+ def Connection.open(login = "", passcode = "", host='localhost', port=61613, reliable=FALSE, reconnectDelay=5)
+ Connection.new login, passcode, host, port, reliable, reconnectDelay
end
# Create a connection, requires a login and passcode.
# Can accept a host (default is localhost), and port
# (default is 61613) to connect to
- def initialize(login, passcode, host='localhost', port=61613, reliable=FALSE)
+ def initialize(login, passcode, host='localhost', port=61613, reliable=false, reconnectDelay=5)
@host = host
@port = port
@login = login
@passcode = passcode
@transmit_semaphore = Mutex.new
@read_semaphore = Mutex.new
@socket_semaphore = Mutex.new
@reliable = reliable
- @reconnectDelay = 5
+ @reconnectDelay = reconnectDelay
@closed = FALSE
@subscriptions = {}
@failure = NIL
socket
end
@@ -124,11 +124,11 @@
def unsubscribe(name, headers = {}, subId=NIL)
headers[:destination] = name
transmit "UNSUBSCRIBE", headers
if @reliable
subId = name if subId==NIL
- @h.delete(subId)
+ @subscriptions.delete(subId)
end
end
# Send message to destination
#
@@ -151,11 +151,11 @@
return receive
end
end
# Receive a frame, block until the frame is received
- def receive
+ def __old_receive
# The recive my fail so we may need to retry.
while TRUE
begin
s = socket
return _receive(s)
@@ -164,16 +164,26 @@
raise unless @reliable
$stderr.print "receive failed: " + $!;
end
end
end
-
+
+ def receive
+ super_result = __old_receive()
+ if super_result.nil? && @reliable
+ $stderr.print "connection.receive returning EOF as nil - resetting connection.\n"
+ @socket = nil
+ super_result = __old_receive()
+ end
+ return super_result
+ end
+
private
def _receive( s )
line = ' '
@read_semaphore.synchronize do
- line = s.gets
+ line = s.gets while line =~ /^\s*$/
return NIL if line == NIL
Message.new do |m|
m.command = line.chomp
m.headers = {}
until (line = s.gets.chomp) == ''
@@ -190,11 +200,11 @@
m.body = ''
until (c = s.getc) == 0
m.body << c.chr
end
end
- c = s.getc
- raise "Invalid frame termination received" unless c == 10
+ #c = s.getc
+ #raise "Invalid frame termination received" unless c == 10
end
end
end
private