[ruby/openssl] Add support for IO#timeout.
(https://github.com/ruby/openssl/pull/714) * Add support for IO#timeout. https://github.com/ruby/openssl/commit/3bbf5178a9
This commit is contained in:
parent
6213ab1a51
commit
4f634d3c85
@ -49,6 +49,7 @@ $defs.push("-D""OPENSSL_SUPPRESS_DEPRECATED")
|
||||
|
||||
have_func("rb_io_descriptor")
|
||||
have_func("rb_io_maybe_wait(0, Qnil, Qnil, Qnil)", "ruby/io.h") # Ruby 3.1
|
||||
have_func("rb_io_timeout", "ruby/io.h")
|
||||
|
||||
Logging::message "=== Checking for system dependent stuff... ===\n"
|
||||
have_library("nsl", "t_open")
|
||||
|
@ -299,6 +299,16 @@ ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
|
||||
def wait_writable(*args)
|
||||
to_io.wait_writable(*args)
|
||||
end
|
||||
|
||||
if IO.method_defined?(:timeout)
|
||||
def timeout
|
||||
to_io.timeout
|
||||
end
|
||||
|
||||
def timeout=(value)
|
||||
to_io.timeout=(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def verify_certificate_identity(cert, hostname)
|
||||
|
@ -1725,11 +1725,20 @@ no_exception_p(VALUE opts)
|
||||
#define RUBY_IO_TIMEOUT_DEFAULT Qnil
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RB_IO_TIMEOUT
|
||||
#define IO_TIMEOUT_ERROR rb_eIOTimeoutError
|
||||
#else
|
||||
#define IO_TIMEOUT_ERROR rb_eIOError
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
io_wait_writable(VALUE io)
|
||||
{
|
||||
#ifdef HAVE_RB_IO_MAYBE_WAIT
|
||||
rb_io_maybe_wait_writable(errno, io, RUBY_IO_TIMEOUT_DEFAULT);
|
||||
if (!rb_io_maybe_wait_writable(errno, io, RUBY_IO_TIMEOUT_DEFAULT)) {
|
||||
rb_raise(IO_TIMEOUT_ERROR, "Timed out while waiting to become writable!");
|
||||
}
|
||||
#else
|
||||
rb_io_t *fptr;
|
||||
GetOpenFile(io, fptr);
|
||||
@ -1741,7 +1750,9 @@ static void
|
||||
io_wait_readable(VALUE io)
|
||||
{
|
||||
#ifdef HAVE_RB_IO_MAYBE_WAIT
|
||||
rb_io_maybe_wait_readable(errno, io, RUBY_IO_TIMEOUT_DEFAULT);
|
||||
if (!rb_io_maybe_wait_readable(errno, io, RUBY_IO_TIMEOUT_DEFAULT)) {
|
||||
rb_raise(IO_TIMEOUT_ERROR, "Timed out while waiting to become readable!");
|
||||
}
|
||||
#else
|
||||
rb_io_t *fptr;
|
||||
GetOpenFile(io, fptr);
|
||||
|
@ -193,6 +193,24 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
|
||||
}
|
||||
end
|
||||
|
||||
def test_read_with_timeout
|
||||
omit "does not support timeout" unless IO.method_defined?(:timeout)
|
||||
|
||||
start_server do |port|
|
||||
server_connect(port) do |ssl|
|
||||
str = +("x" * 100 + "\n")
|
||||
ssl.syswrite(str)
|
||||
assert_equal(str, ssl.sysread(str.bytesize))
|
||||
|
||||
ssl.timeout = 1
|
||||
assert_raise(IO::TimeoutError) {ssl.read(1)}
|
||||
|
||||
ssl.syswrite(str)
|
||||
assert_equal(str, ssl.sysread(str.bytesize))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_getbyte
|
||||
start_server { |port|
|
||||
server_connect(port) { |ssl|
|
||||
|
Loading…
x
Reference in New Issue
Block a user