Skip to content
Browse files

add eof check to socket read

  • Loading branch information...
1 parent eed6330 commit eaaaf1be47135239c433854ec0582f7c05d3a0e9 @mojombo committed Feb 24, 2010
Showing with 12 additions and 0 deletions.
  1. +3 −0 lib/bertrpc/action.rb
  2. +9 −0 lib/bertrpc/errors.rb
View
3 lib/bertrpc/action.rb
@@ -29,6 +29,7 @@ def read(sock, len, timeout)
r, w, e = IO.select([sock], [], [], timeout)
raise Errno::EAGAIN if r.nil?
msg, sender = sock.recvfrom(len - size)
+ raise Errno::ECONNRESET if msg.size == 0
size += msg.size
data << msg
end
@@ -59,6 +60,8 @@ def transaction(bert_request)
raise ConnectionError.new("Unable to connect to #{@svc.host}:#{@svc.port}")
rescue Errno::EAGAIN
raise ReadTimeoutError.new(@svc.host, @svc.port, @svc.timeout)
+ rescue Errno::ECONNRESET
+ raise ReadError.new(@svc.host, @svc.port)
end
# Creates a socket object which does speedy, non-blocking reads
View
9 lib/bertrpc/errors.rb
@@ -40,6 +40,15 @@ def initialize(host, port, timeout)
end
end
+ # Raised when unexpected EOF is reached on the socket.
+ class ReadError < BERTRPCError
+ attr_reader :host, :port
+ def initialize(host, port)
+ @host, @port = host, port
+ super("Unable to read from #{host}:#{port}")
+ end
+ end
+
class ProtocolError < BERTRPCError
NO_HEADER = [0, "Unable to read length header from server."]
NO_DATA = [1, "Unable to read data from server."]

0 comments on commit eaaaf1b

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