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:



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

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

Instance Method Details

#closeObject

def write



107
108
109
110
111
# File 'lib/logstash/outputs/tcp.rb', line 107

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

#runObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/logstash/outputs/tcp.rb', line 88

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



103
104
105
# File 'lib/logstash/outputs/tcp.rb', line 103

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