aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2024-04-16 14:52:58 +0200
committerJean Boussier <jean.boussier@gmail.com>2024-05-02 10:16:47 +0200
commit08452993d6834352b0227f3368ee9144239e9803 (patch)
tree5c0d25774575348bd1c6d10d8290d0e7d324a171 /ext/openssl
parent97305cfafc4e06c67e8b2d96fd72acc83597db05 (diff)
downloadruby-openssl-08452993d6834352b0227f3368ee9144239e9803.tar.gz
read: don't clear buffer when nothing can be read
To be consistent with regular Ruby IOs: ```ruby r, _ = IO.pipe buf = "garbage".b r.read_nonblock(10, buf, exception: false) # => :wait_readable p buf # => "garbage" ``` Ref: https://github.com/redis-rb/redis-client/commit/98b8944460a11f8508217bda71cfc10cb2190d4d
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/ossl_ssl.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 9f374b65..d68c64d5 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1958,9 +1958,11 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
else
rb_str_modify_expand(str, ilen - RSTRING_LEN(str));
}
- rb_str_set_len(str, 0);
- if (ilen == 0)
- return str;
+
+ if (ilen == 0) {
+ rb_str_set_len(str, 0);
+ return str;
+ }
VALUE io = rb_attr_get(self, id_i_io);