Skip to content

Allow setting sockstreambuf buffer size and max putback#3154

Merged
davisking merged 3 commits into
davisking:masterfrom
kSkip:sockstreambuf-ctor-args
Jul 19, 2026
Merged

Allow setting sockstreambuf buffer size and max putback#3154
davisking merged 3 commits into
davisking:masterfrom
kSkip:sockstreambuf-ctor-args

Conversation

@kSkip

@kSkip kSkip commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

I would like to use the sockstreambuf with a larger buffer size, and think it would be nice to adjust the max put back as well. In addition, I also changed the buffer pointers to unique_ptr. I figured that was just pre-C++11 code.

Comment on lines -101 to +106
setp(out_buffer, out_buffer + (out_buffer_size-1));
setg(in_buffer+max_putback,
in_buffer+max_putback,
in_buffer+max_putback);
setp(out_buffer.get(), out_buffer.get() + (out_buffer_size-1));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For here, should this be out_buffer + out_buffer_size? Because epptr is defined as "one past the end of the put area". If I understand this correctly, the effective buffer size will be 1 char smaller if we use out_buffer_size-1

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yeah epptr() is one past the put area, but the final allocated byte is deliberately excluded from that put area because this implementation uses it to hold the character that triggered overflow(). So it's fine, it's just a matter of how the other parts of the code define it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cool, thanks for explaining. I find the std::streambuf interface really confusing sometimes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yeah it's somewhat bizarre

@davisking

Copy link
Copy Markdown
Owner

Looks good. I just fixed std::unique_ptr<char> needing to be std::unique_ptr<char[]> and pushed some cleanup stuff. Once all the tests run I'll merge it :D

Thanks for another PR.

@kSkip

kSkip commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

I just fixed std::unique_ptr<char> needing to be std::unique_ptr<char[]>

Oh, good catch. Thanks for the help.

@davisking
davisking merged commit 19f6be7 into davisking:master Jul 19, 2026
9 checks passed
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.

2 participants