Class: LogStash::Outputs::Tcp::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/tcp.rb

Instance Method Summary collapse

Constructor Details

#initialize(socket, logger_context) ⇒ Client

Returns a new instance of Client.

Parameters:



62
63
64
65
66
# File 'lib/logstash/outputs/tcp.rb', line 62

def initialize(socket, logger_context)
  @socket = socket
  @logger_context = logger_context
  @queue  = Queue.new
end

Instance Method Details

#closeObject

def write



87
88
89
90
91
# File 'lib/logstash/outputs/tcp.rb', line 87

def close
  @socket.close
rescue => e
  @logger_context.log_warn 'socket close failed:', e, socket: (@socket ? @socket.to_s : nil)
end

#runObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/logstash/outputs/tcp.rb', line 68

def run
  loop do
    begin
      remaining_payload = @queue.pop
      while remaining_payload && remaining_payload.bytesize > 0
        written_bytes_size = @socket.write(remaining_payload)
        remaining_payload = remaining_payload.byteslice(written_bytes_size..-1)
      end
    rescue => e
      @logger_context.log_warn 'socket write failed:', e, socket: (@socket ? @socket.to_s : nil)
      break
    end
  end
end

#write(msg) ⇒ Object

def run



83
84
85
# File 'lib/logstash/outputs/tcp.rb', line 83

def write(msg)
  @queue.push(msg)
end