Class: LogStash::Inputs::Syslog::TCPInput

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/logstash/inputs/syslog.rb

Instance Method Summary collapse

Constructor Details

#initialize(receiver, logger) ⇒ TCPInput

Returns a new instance of TCPInput.



98
99
100
101
102
# File 'lib/logstash/inputs/syslog.rb', line 98

def initialize(receiver, logger)
  @logger = logger
  @receiver = receiver
  @buffer = BufferedTokenizer.new  # From eventmachine
end

Instance Method Details

#receive_data(data) ⇒ Object

Messages over TCP may not be received all at once, chunk by newline.



105
106
107
108
109
110
111
# File 'lib/logstash/inputs/syslog.rb', line 105

def receive_data(data)
  @buffer.extract(data).each do |line|
    port, host = Socket.unpack_sockaddr_in(self.get_peername)
    # Trim trailing newlines 
    @receiver.receive(host, port, line.chomp)
  end
end