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:



92
93
94
95
96
# File 'lib/logstash/outputs/tcp.rb', line 92

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

Instance Method Details

#closeObject

def write



117
118
119
120
121
# File 'lib/logstash/outputs/tcp.rb', line 117

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

#runObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/logstash/outputs/tcp.rb', line 98

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



113
114
115
# File 'lib/logstash/outputs/tcp.rb', line 113

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