lib/remote_syslog/reader.rb in remote_syslog-1.2.1 vs lib/remote_syslog/reader.rb in remote_syslog-1.3.0
- old
+ new
@@ -9,17 +9,14 @@
COLORED_REGEXP = /\e\[(?:(?:[34][0-7]|[0-9]);){0,2}(?:[34][0-7]|[0-9])m/
def initialize(path, destination_address, destination_port, options = {})
super(path, -1)
- @destination_address = destination_address
- @destination_port = destination_port.to_i
-
@parse_fields = options[:parse_fields]
@strip_color = options[:strip_color]
- @socket = options[:socket] || EventMachine.open_datagram_socket('0.0.0.0', 0)
+ @socket = options[:socket] || UdpEndpoint.new(destination_address, destination_port)
@buffer = BufferedTokenizer.new
@packet = SyslogProtocol::Packet.new
@@ -35,37 +32,18 @@
# Make sure the tag isn't too long
if @packet.tag.length > 32
@packet.tag = @packet.tag[0..31]
end
-
- # Try to resolve the destination address
- resolve_destination_address
-
- # Every 60 seconds we'll see if the address has changed
- EventMachine.add_periodic_timer(60) do
- resolve_destination_address
- end
end
- def resolve_destination_address
- request = EventMachine::DnsResolver.resolve(@destination_address)
- request.callback do |addrs|
- @cached_destination_ip = addrs.first
- end
- end
-
def receive_data(data)
@buffer.extract(data).each do |line|
transmit(line)
end
end
- def destination_address
- @cached_destination_ip || @destination_address
- end
-
def transmit(message)
message = message.gsub(COLORED_REGEXP, '') if @strip_color
packet = @packet.dup
packet.content = message
@@ -76,9 +54,9 @@
packet.tag = $3 if $3 && $2 != ''
packet.content = $4 if $4 && $4 != ''
end
end
- @socket.send_datagram(packet.assemble, destination_address, @destination_port)
+ @socket.write(packet.assemble)
end
end
end