Skip to content

Commit 8d928e0

Browse files
ioquatixrhenium
authored andcommitted
Deprecate and rework old (fd) centric functions
[ky: fixed compatibility with older versions of Ruby] (cherry picked from commit ruby/ruby@45e65f3)
1 parent 5f8160a commit 8d928e0

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

ext/openssl/extconf.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
$defs.push("-DOSSL_DEBUG")
2727
end
2828

29+
have_func("rb_io_maybe_wait") # Ruby 3.1
30+
2931
Logging::message "=== Checking for system dependent stuff... ===\n"
3032
have_library("nsl", "t_open")
3133
have_library("socket", "socket")

ext/openssl/ossl_ssl.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,26 @@ no_exception_p(VALUE opts)
15321532
return 0;
15331533
}
15341534

1535+
static void
1536+
io_wait_writable(rb_io_t *fptr)
1537+
{
1538+
#ifdef HAVE_RB_IO_MAYBE_WAIT
1539+
rb_io_maybe_wait_writable(errno, fptr->self, Qnil);
1540+
#else
1541+
rb_io_wait_writable(fptr->fd);
1542+
#endif
1543+
}
1544+
1545+
static void
1546+
io_wait_readable(rb_io_t *fptr)
1547+
{
1548+
#ifdef HAVE_RB_IO_MAYBE_WAIT
1549+
rb_io_maybe_wait_readable(errno, fptr->self, Qnil);
1550+
#else
1551+
rb_io_wait_readable(fptr->fd);
1552+
#endif
1553+
}
1554+
15351555
static VALUE
15361556
ossl_start_ssl(VALUE self, int (*func)(), const char *funcname, VALUE opts)
15371557
{
@@ -1566,12 +1586,12 @@ ossl_start_ssl(VALUE self, int (*func)(), const char *funcname, VALUE opts)
15661586
case SSL_ERROR_WANT_WRITE:
15671587
if (no_exception_p(opts)) { return sym_wait_writable; }
15681588
write_would_block(nonblock);
1569-
rb_io_wait_writable(fptr->fd);
1589+
io_wait_writable(fptr);
15701590
continue;
15711591
case SSL_ERROR_WANT_READ:
15721592
if (no_exception_p(opts)) { return sym_wait_readable; }
15731593
read_would_block(nonblock);
1574-
rb_io_wait_readable(fptr->fd);
1594+
io_wait_readable(fptr);
15751595
continue;
15761596
case SSL_ERROR_SYSCALL:
15771597
#ifdef __APPLE__
@@ -1749,12 +1769,12 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
17491769
case SSL_ERROR_WANT_WRITE:
17501770
if (no_exception_p(opts)) { return sym_wait_writable; }
17511771
write_would_block(nonblock);
1752-
rb_io_wait_writable(fptr->fd);
1772+
io_wait_writable(fptr);
17531773
continue;
17541774
case SSL_ERROR_WANT_READ:
17551775
if (no_exception_p(opts)) { return sym_wait_readable; }
17561776
read_would_block(nonblock);
1757-
rb_io_wait_readable(fptr->fd);
1777+
io_wait_readable(fptr);
17581778
continue;
17591779
case SSL_ERROR_SYSCALL:
17601780
if (!ERR_peek_error()) {
@@ -1865,12 +1885,12 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
18651885
case SSL_ERROR_WANT_WRITE:
18661886
if (no_exception_p(opts)) { return sym_wait_writable; }
18671887
write_would_block(nonblock);
1868-
rb_io_wait_writable(fptr->fd);
1888+
io_wait_writable(fptr);
18691889
continue;
18701890
case SSL_ERROR_WANT_READ:
18711891
if (no_exception_p(opts)) { return sym_wait_readable; }
18721892
read_would_block(nonblock);
1873-
rb_io_wait_readable(fptr->fd);
1893+
io_wait_readable(fptr);
18741894
continue;
18751895
case SSL_ERROR_SYSCALL:
18761896
#ifdef __APPLE__

0 commit comments

Comments
 (0)