Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup server helper #1759

Merged
merged 4 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fluent/plugin/in_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def start_tcp_server
delimiter = "\n"
delimiter_size = delimiter.size
server_create_connection(:in_syslog_tcp_server, @port, bind: @bind, resolve_name: @resolve_hostname) do |conn|
buffer = ""
conn.data do |data|
buffer = conn.buffer
buffer << data
pos = 0
while idx = buffer.index(delimiter, pos)
Expand Down
19 changes: 14 additions & 5 deletions lib/fluent/plugin_helper/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ def server_create_udp_socket(shared, bind, port)
sock
end

# Use string "?" for port, not integer or nil. "?" is clear than -1 or nil in the log.
PEERADDR_FAILED = ["?", "?", "name resolusion failed", "?"]

class CallbackSocket
def initialize(server_type, sock, enabled_events = [], close_socket: true)
@server_type = server_type
Expand Down Expand Up @@ -425,11 +428,13 @@ def on(event, &callback)
end

class TCPCallbackSocket < CallbackSocket
ENABLED_EVENTS = [:data, :write_complete, :close]

attr_accessor :buffer

def initialize(sock)
super("tcp", sock, [:data, :write_complete, :close])
@peeraddr = @sock.peeraddr
super("tcp", sock, ENABLED_EVENTS)
@peeraddr = (@sock.peeraddr rescue PEERADDR_FAILED)
@buffer = ''
end

Expand All @@ -439,9 +444,11 @@ def write(data)
end

class TLSCallbackSocket < CallbackSocket
ENABLED_EVENTS = [:data, :write_complete, :close]

def initialize(sock)
super("tls", sock, [:data, :write_complete, :close])
@peeraddr = @sock.to_io.peeraddr
super("tls", sock, ENABLED_EVENTS)
@peeraddr = (@sock.to_io.peeraddr rescue PEERADDR_FAILED)
end

def write(data)
Expand All @@ -450,8 +457,10 @@ def write(data)
end

class UDPCallbackSocket < CallbackSocket
ENABLED_EVENTS = []

def initialize(sock, peeraddr, **kwargs)
super("udp", sock, [], **kwargs)
super("udp", sock, ENABLED_EVENTS, **kwargs)
@peeraddr = peeraddr
end

Expand Down