summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
authorSamuel Williams <[email protected]>2022-10-07 21:48:38 +1300
committerGitHub <[email protected]>2022-10-07 21:48:38 +1300
commite4f91bbdbaa6ab3125f24967414ac5300bb244f5 (patch)
tree575f8febdd50601522c5e5ec72f3436139304537 /ext/openssl
parente76217a7f3957c9cea52832c2f4237130411f7dd (diff)
Add IO#timeout attribute and use it for blocking IO operations. (#5653)
Notes
Notes: Merged-By: ioquatix <[email protected]>
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/extconf.rb1
-rw-r--r--ext/openssl/ossl_ssl.c14
2 files changed, 13 insertions, 2 deletions
diff --git a/ext/openssl/extconf.rb b/ext/openssl/extconf.rb
index cc2b1f8ba2..a856646fe5 100644
--- a/ext/openssl/extconf.rb
+++ b/ext/openssl/extconf.rb
@@ -27,6 +27,7 @@ if with_config("debug") or enable_config("debug")
end
have_func("rb_io_maybe_wait") # Ruby 3.1
+have_func("rb_io_timeout") # Ruby 3.2
Logging::message "=== Checking for system dependent stuff... ===\n"
have_library("nsl", "t_open")
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 6e1a50fd6d..605591efe5 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1641,11 +1641,21 @@ no_exception_p(VALUE opts)
return 0;
}
+inline static
+VALUE io_timeout()
+{
+#ifdef HAVE_RB_IO_TIMEOUT
+ return Qundef;
+#else
+ return Qnil;
+#endif
+}
+
static void
io_wait_writable(rb_io_t *fptr)
{
#ifdef HAVE_RB_IO_MAYBE_WAIT
- rb_io_maybe_wait_writable(errno, fptr->self, Qnil);
+ rb_io_maybe_wait_writable(errno, fptr->self, io_timeout());
#else
rb_io_wait_writable(fptr->fd);
#endif
@@ -1655,7 +1665,7 @@ static void
io_wait_readable(rb_io_t *fptr)
{
#ifdef HAVE_RB_IO_MAYBE_WAIT
- rb_io_maybe_wait_readable(errno, fptr->self, Qnil);
+ rb_io_maybe_wait_readable(errno, fptr->self, io_timeout());
#else
rb_io_wait_readable(fptr->fd);
#endif