summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2021-06-19 13:47:16 +1200
committerKazuki Yamaguchi <k@rhe.jp>2021-07-18 17:48:49 +0900
commit3f1d8a18eac7d775e69b99f761e756f2abb60c12 (patch)
tree9e85019f55f51ce29d5de6dbf0629f9800f9fde6 /ext/openssl
parent397584078006946ec3673d30b4810334c1a5f06d (diff)
[ruby/openssl] Deprecate and rework old (fd) centric functions
[ky: fixed compatibility with older versions of Ruby] (cherry picked from commit ruby/ruby@45e65f302b663b2c6ab69df06d3b6f219c1797b2) https://github.com/ruby/openssl/commit/8d928e0fb9
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/extconf.rb2
-rw-r--r--ext/openssl/ossl_ssl.c32
2 files changed, 28 insertions, 6 deletions
diff --git a/ext/openssl/extconf.rb b/ext/openssl/extconf.rb
index 8812b7de862..aa4eae824c7 100644
--- a/ext/openssl/extconf.rb
+++ b/ext/openssl/extconf.rb
@@ -26,6 +26,8 @@ if with_config("debug") or enable_config("debug")
$defs.push("-DOSSL_DEBUG")
end
+have_func("rb_io_maybe_wait") # Ruby 3.1
+
Logging::message "=== Checking for system dependent stuff... ===\n"
have_library("nsl", "t_open")
have_library("socket", "socket")
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index e9e37dc9e38..380b18e71c0 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1532,6 +1532,26 @@ no_exception_p(VALUE opts)
return 0;
}
+static void
+io_wait_writable(rb_io_t *fptr)
+{
+#ifdef HAVE_RB_IO_MAYBE_WAIT
+ rb_io_maybe_wait_writable(errno, fptr->self, Qnil);
+#else
+ rb_io_wait_writable(fptr->fd);
+#endif
+}
+
+static void
+io_wait_readable(rb_io_t *fptr)
+{
+#ifdef HAVE_RB_IO_MAYBE_WAIT
+ rb_io_maybe_wait_readable(errno, fptr->self, Qnil);
+#else
+ rb_io_wait_readable(fptr->fd);
+#endif
+}
+
static VALUE
ossl_start_ssl(VALUE self, int (*func)(), const char *funcname, VALUE opts)
{
@@ -1566,12 +1586,12 @@ ossl_start_ssl(VALUE self, int (*func)(), const char *funcname, VALUE opts)
case SSL_ERROR_WANT_WRITE:
if (no_exception_p(opts)) { return sym_wait_writable; }
write_would_block(nonblock);
- rb_io_maybe_wait_writable(errno, fptr->self, Qnil);
+ io_wait_writable(fptr);
continue;
case SSL_ERROR_WANT_READ:
if (no_exception_p(opts)) { return sym_wait_readable; }
read_would_block(nonblock);
- rb_io_maybe_wait_readable(errno, fptr->self, Qnil);
+ io_wait_readable(fptr);
continue;
case SSL_ERROR_SYSCALL:
#ifdef __APPLE__
@@ -1749,12 +1769,12 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
case SSL_ERROR_WANT_WRITE:
if (no_exception_p(opts)) { return sym_wait_writable; }
write_would_block(nonblock);
- rb_io_maybe_wait_writable(errno, fptr->self, Qnil);
+ io_wait_writable(fptr);
continue;
case SSL_ERROR_WANT_READ:
if (no_exception_p(opts)) { return sym_wait_readable; }
read_would_block(nonblock);
- rb_io_maybe_wait_readable(errno, fptr->self, Qnil);
+ io_wait_readable(fptr);
continue;
case SSL_ERROR_SYSCALL:
if (!ERR_peek_error()) {
@@ -1865,12 +1885,12 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
case SSL_ERROR_WANT_WRITE:
if (no_exception_p(opts)) { return sym_wait_writable; }
write_would_block(nonblock);
- rb_io_maybe_wait_writable(errno, fptr->self, Qnil);
+ io_wait_writable(fptr);
continue;
case SSL_ERROR_WANT_READ:
if (no_exception_p(opts)) { return sym_wait_readable; }
read_would_block(nonblock);
- rb_io_maybe_wait_readable(errno, fptr->self, Qnil);
+ io_wait_readable(fptr);
continue;
case SSL_ERROR_SYSCALL:
#ifdef __APPLE__