lib/logstash/util/relp.rb in logstash-input-relp-0.1.2 vs lib/logstash/util/relp.rb in logstash-input-relp-0.1.3
- old
+ new
@@ -8,10 +8,11 @@
class RelpError < StandardError; end
class InvalidCommand < RelpError; end
class InappropriateCommand < RelpError; end
class ConnectionClosed < RelpError; end
+ class FrameReadException < RelpError; end
class InsufficientCommands < RelpError; end
def valid_command?(command)
valid_commands = Array.new
@@ -73,12 +74,14 @@
else
frame['datalen'] = (leading_digit + socket.readline(' ')).strip.to_i
frame['message'] = socket.read(frame['datalen'])
end
@logger.debug? and @logger.debug("Read frame", :frame => frame)
- rescue EOFError,Errno::ECONNRESET,IOError
+ rescue Errno::ECONNRESET
raise ConnectionClosed
+ rescue EOFError,IOError
+ raise FrameReadException
end
if ! self.valid_command?(frame['command'])#TODO: is this enough to catch framing errors?
if self.server?
self.serverclose(socket)
else
@@ -118,10 +121,15 @@
@logger.info? and @logger.info("Started RELP Server", :host => host, :port => port)
end
def accept
socket = @server.accept
+ @logger.debug("New socket created")
+ return self, socket
+ end
+
+ def relp_setup_connection(socket)
frame=self.frame_read(socket)
if frame['command'] == 'open'
offer=Hash[*frame['message'].scan(/^(.*)=(.*)$/).flatten]
if offer['relp_version'].nil?
@logger.warn("No relp version specified")
@@ -151,10 +159,9 @@
response_frame['message'] = '200 OK '
response_frame['message'] += 'relp_version=' + RelpVersion + "\n"
response_frame['message'] += 'relp_software=' + RelpSoftware + "\n"
response_frame['message'] += 'commands=' + @required_relp_commands.join(',')#TODO: optional ones
self.frame_write(socket, response_frame)
- return self, socket
end
else
self.serverclose(socket)
raise InappropriateCommand, frame['command'] + ' expecting open'
end