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 3 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
18 changes: 13 additions & 5 deletions lib/fluent/plugin_helper/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ def server_create_udp_socket(shared, bind, port)
sock
end

PEERADDR_FAILED = ["?", "?", "name resolusion failed", "?"]
Copy link
Member

@mururu mururu Nov 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor comment: remote_port usually returns Integer, but it returns String when failed. It is a little confusing. So it seems better to have comment about that it may return string at remote_port definition.


class CallbackSocket
def initialize(server_type, sock, enabled_events = [], close_socket: true)
@server_type = server_type
Expand Down Expand Up @@ -425,11 +427,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 +443,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 +456,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