Skip to content
Browse files

Fixing client retry functionality, error if no messages present and l…

…ast parameter given
  • Loading branch information...
1 parent 589212b commit ea08f54b00f20c60ded288aa1ac55931876bbec8 @winton committed Jan 16, 2011
Showing with 21 additions and 16 deletions.
  1. +12 −9 lib/puggernaut/client.rb
  2. +2 −3 lib/puggernaut/server/http.rb
  3. +7 −4 lib/puggernaut/server/room.rb
View
21 lib/puggernaut/client.rb
@@ -45,24 +45,27 @@ def say(messages)
private
- def send(host, port, data, try_again=true)
- if try_again
- @retry.length.times do
- host, port, data = @retry.shift
- @connections.delete("#{host}:#{port}")
- send host, port, data, false
- end
- end
+ def send(host, port, data, try_retry=true)
+ try if try_retry
begin
logger.info "Client#send - #{host}:#{port} - #{data}"
connection = connect(host, port)
connection.print(data)
- raise 'not ok' unless connection.gets.include?('OK')
+ response = connection.gets
+ raise 'not ok' if !response || !response.include?('OK')
rescue Exception => e
logger.info "Client#send - Exception - #{e.message} - #{host}:#{port} - #{data}"
@retry << [ host, port, data ]
@retry.shift if @retry.length > 10
end
end
+
+ def try
+ @retry.length.times do
+ host, port, data = @retry.shift
+ @connections.delete("#{host}:#{port}")
+ send host, port, data, false
+ end
+ end
end
end
View
5 lib/puggernaut/server/http.rb
@@ -24,9 +24,8 @@ def receive_data(data)
if path == '/'
if query && !query['room'].empty?
- @rooms = query['room'].inject([]) do |array, room|
- array << (Puggernaut::Server.rooms[room] ||= Room.new(room))
- array
+ @rooms = query['room'].collect do |room|
+ Puggernaut::Server.rooms[room] ||= Room.new(room)
end
if query['last'] && !query['last'].empty?
last = query['last'].dup
View
11 lib/puggernaut/server/room.rb
@@ -12,10 +12,13 @@ def initialize(room)
def all_messages_after(identifier)
found = false
- @messages.select { |(id, message)|
- found = true if id == identifier
- found
- }[1..-1].collect { |message|
+ (
+ @messages.select { |(id, message)|
+ found = true if id == identifier
+ found
+ }[1..-1] || []
+
+ ).collect { |message|
"#{@room}|#{message.join '|'}"
}
end

0 comments on commit ea08f54

Please sign in to comment.
Something went wrong with that request. Please try again.