ruby / openssl

Provides SSL, TLS and general purpose cryptography.
Other
240 stars 167 forks source link

Add SSLSocket#readbyte #771

Closed lwoggardner closed 4 months ago

lwoggardner commented 4 months ago

Companion to getbyte but raise EOFError Similar to https://github.com/ruby/openssl/pull/438

rhenium commented 4 months ago

Looks good to me. Thank you for your PR!

lwoggardner commented 4 months ago

Thanks @rhenium glad to help.

One question if I may.

My first inclination was to do

getbyte or raise EOFError

ie obvious that there is no way of getting a nil return if somehow EOF occurs between the eof? check and getbyte. This is also seems to be the approach used in the MRI C code for IO::readbyte.

But then I saw all the existing methods used this form...

raise EOFError if eof?
getbyte

I understand that this works because eof? has a side effect of pulling data into the buffer. My question is whether this was a concious choice for performance or some other reason? (and if not would you consider changing it?)