[ruby/openssl] 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: 98b8944460
https://github.com/ruby/openssl/commit/08452993d6
This commit is contained in:
parent
fca6c55a53
commit
7d42010fad
@ -1958,9 +1958,11 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
|
|||||||
else
|
else
|
||||||
rb_str_modify_expand(str, ilen - RSTRING_LEN(str));
|
rb_str_modify_expand(str, ilen - RSTRING_LEN(str));
|
||||||
}
|
}
|
||||||
rb_str_set_len(str, 0);
|
|
||||||
if (ilen == 0)
|
if (ilen == 0) {
|
||||||
return str;
|
rb_str_set_len(str, 0);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
VALUE io = rb_attr_get(self, id_i_io);
|
VALUE io = rb_attr_get(self, id_i_io);
|
||||||
|
|
||||||
|
@ -250,12 +250,17 @@ module OpenSSL::TestPairM
|
|||||||
|
|
||||||
buf = +"garbage"
|
buf = +"garbage"
|
||||||
assert_equal :wait_readable, s2.read_nonblock(100, buf, exception: false)
|
assert_equal :wait_readable, s2.read_nonblock(100, buf, exception: false)
|
||||||
assert_equal "", buf
|
assert_equal "garbage", buf
|
||||||
|
|
||||||
s1.close
|
s1.close
|
||||||
buf = +"garbage"
|
buf = +"garbage"
|
||||||
assert_equal nil, s2.read(100, buf)
|
assert_nil s2.read(100, buf)
|
||||||
assert_equal "", buf
|
assert_equal "", buf
|
||||||
|
|
||||||
|
buf = +"garbage"
|
||||||
|
ret = s2.read(0, buf)
|
||||||
|
assert_same buf, ret
|
||||||
|
assert_equal "", ret
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user