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

Use #slice instead of #slice! #24

Closed
wants to merge 1 commit into from
Closed
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/compat/socket_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def on_read(data)
@callback.call(msg, @addr)
pos = i + @delimiter.length
end
@buffer.slice!(0, pos) if pos > 0
@buffer = @buffer[pos..] if pos > 0
rescue => e
@log.error "unexpected error", error: e
close
Expand Down
5 changes: 4 additions & 1 deletion lib/fluent/plugin/in_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ def start_tcp_server(tls: false)
message_handler(msg, conn)
end
end
buffer.slice!(0, pos) if pos > 0
if pos > 0
buffer = buffer[pos..]
conn.buffer = buffer
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1057,8 +1057,8 @@ def read_lines(lines)
# See https://github.com/fluent/fluentd/pull/2527
@buffer.freeze
slice_position = idx + 1
rbuf = @buffer.slice(0, slice_position)
@buffer = @buffer.slice(slice_position, @buffer.size - slice_position)
rbuf = @buffer[0, slice_position]
@buffer = @buffer[slice_position..]
idx = @buffer.index(@eol)

is_long_line = @max_line_size && (
Expand Down
10 changes: 8 additions & 2 deletions lib/fluent/plugin/in_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ def start
router.emit(tag, time, record)
end
end
buf.slice!(0, pos) if pos > 0
if pos > 0
buf = buf[pos..]
conn.buffer = buf
end
# If the buffer size exceeds the limit here, it means that the next message will definitely exceed the limit.
# So we should clear the buffer here. Otherwise, it will keep storing useless data until the next delimiter comes.
if !@message_length_limit.nil? && @message_length_limit < buf.bytesize
Expand Down Expand Up @@ -198,7 +201,10 @@ def start
end
end
router.emit_stream(@tag, es)
buf.slice!(0, pos) if pos > 0
if pos > 0
buf = buf[pos..]
conn.buffer = buf
end
# If the buffer size exceeds the limit here, it means that the next message will definitely exceed the limit.
# So we should clear the buffer here. Otherwise, it will keep storing useless data until the next delimiter comes.
if !@message_length_limit.nil? && @message_length_limit < buf.bytesize
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/plugin_helper/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ def on_writable
@mutex.synchronize do
# Consider write_nonblock with {exception: false} when IO::WaitWritable error happens frequently.
written_bytes = @_handler_socket.write_nonblock(@_handler_write_buffer)
@_handler_write_buffer.slice!(0, written_bytes)
@_handler_write_buffer = @_handler_write_buffer[written_bytes..]
end

# No need to call `super` in a synchronized context because TLSServer doesn't use the inner buffer(::IO::Buffer) of Coolio::IO.
Expand Down
Loading