Class: Fluent::Plugin::SocketHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_unix_client.rb

Constant Summary collapse

MAX_LENGTH_RECEIVE_ONCE =
10000

Instance Method Summary collapse

Constructor Details

#initialize(path, delimiter: "\n", format_json: false, log: nil) ⇒ SocketHandler

Returns a new instance of SocketHandler.



95
96
97
98
99
100
# File 'lib/fluent/plugin/in_unix_client.rb', line 95

def initialize(path, delimiter: "\n", format_json: false, log: nil)
  @path = path
  @log = log
  @socket = nil
  @buf = Buffer.new(delimiter, format_json: format_json)
end

Instance Method Details

#connected?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/fluent/plugin/in_unix_client.rb', line 102

def connected?
  !@socket.nil?
end

#try_closeObject



124
125
126
127
128
129
130
# File 'lib/fluent/plugin/in_unix_client.rb', line 124

def try_close
  @socket&.close
rescue => e
  @log&.error "in_unix_client: failed to close socket. #{e.message}"
ensure
  @socket = nil
end

#try_receive(timeout: 1) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/fluent/plugin/in_unix_client.rb', line 106

def try_receive(timeout: 1)
  unless connected?
    try_open
    return []
  end
  return [] unless exist_data?(timeout)

  records, has_closed = try_get_records

  if has_closed
    @log&.warn "in_unix_client: server socket seems to be closed."
    try_close
    return []
  end

  records
end