Sha256: 0b969809e068b91ffaa0c9d49b5c2f605b6ca0b05314c130e499efb831c04555

Contents?: true

Size: 837 Bytes

Versions: 4

Compression:

Stored size: 837 Bytes

Contents

#!/usr/bin/env ruby

require 'socket'

class Client
  def initialize(host, port)
    @host = host
    @port = port
    @count = 0
  end

  def write_safely(data)
    connect_socket unless @connected
    begin
      @client.puts(data)
      sleep 0.01
    rescue
      @connected = false
    end
  end

  def close
    @client.close if @client && @connected
  end

  private
    def connect_socket
      begin
        @client = TCPSocket.new(@host, @port)
        @connected = true
      rescue
        @connected = false
      end
    end
end

client = Client.new("127.0.0.1", "10000")

while !$stdin.eof?
  line = $stdin.readline
  entries = line.split("\n")
  # Assume that no meaningful line will be less than this
  entries.each do |e|
    if e.length > 10
      client.write_safely(e)
    end
  end
  $stdout.flush
end
client.close

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nfagent-0.9.50 bin/squid_log_writer
nfagent-0.9.30 bin/squid_log_writer
nfagent-0.9.29 bin/squid_log_writer
nfagent-0.9.28 bin/squid_log_writer