Skip to content

Respect unread buffered data when checking EOF - #68

Open
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/eof-buffered-io
Open

Respect unread buffered data when checking EOF#68
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/eof-buffered-io

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Return false from BufferedIO#eof? while unread bytes remain in its own buffer. Only ask the underlying IO after that buffer is exhausted.

Reproduction

require 'net/protocol'
require 'stringio'
io = Net::BufferedIO.new(StringIO.new("one\ntwo\n"))
p io.readline # "one"
p io.eof?     # before: true; after: false
p io.readline # "two"
p io.eof?     # true

A bounded local Socket.pair reproduction also shows the old eof? blocking while a complete second line is already buffered and the peer remains open. The patched call returns false without waiting. The remaining buffered line is preserved when the peer closes.

Verification

Compatibility and limitations

No signature changes. eof? intentionally stops reporting EOF, or waiting on the underlying socket, while this wrapper still has unread data.

The patch also applies to installed release 0.3.0, whose runtime file matches the reviewed master. Gem version, dependencies and Ruby >= 2.6 requirement stay unchanged. Only macOS/Ruby 4.0.6 was run locally; other Ruby/OS combinations require upstream CI. No production traffic or external service was used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant