Class: LogStash::Outputs::Tcp::Client
- Inherits:
-
Object
- Object
- LogStash::Outputs::Tcp::Client
- Defined in:
- lib/logstash/outputs/tcp.rb
Instance Method Summary collapse
-
#close ⇒ Object
def write.
-
#initialize(socket, logger_context) ⇒ Client
constructor
A new instance of Client.
- #run ⇒ Object
-
#write(msg) ⇒ Object
def run.
Constructor Details
#initialize(socket, logger_context) ⇒ Client
Returns a new instance of Client.
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
#close ⇒ Object
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 |
#run ⇒ Object
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 |