[ruby/openssl] Remove usage of IO internals.
This commit is contained in:
parent
764207e47c
commit
98f500d095
@ -27,6 +27,7 @@ if with_config("debug") or enable_config("debug")
|
|||||||
end
|
end
|
||||||
$defs.push("-D""OPENSSL_SUPPRESS_DEPRECATED")
|
$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_maybe_wait(0, Qnil, Qnil, Qnil)", "ruby/io.h") # Ruby 3.1
|
||||||
|
|
||||||
Logging::message "=== Checking for system dependent stuff... ===\n"
|
Logging::message "=== Checking for system dependent stuff... ===\n"
|
||||||
|
@ -1653,6 +1653,17 @@ ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_RB_IO_DESCRIPTOR
|
||||||
|
static int
|
||||||
|
io_descriptor_fallback(VALUE io)
|
||||||
|
{
|
||||||
|
rb_io_t *fptr;
|
||||||
|
GetOpenFile(io, fptr);
|
||||||
|
return fptr->fd;
|
||||||
|
}
|
||||||
|
#define rb_io_descriptor io_descriptor_fallback
|
||||||
|
#endif
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
ossl_ssl_setup(VALUE self)
|
ossl_ssl_setup(VALUE self)
|
||||||
{
|
{
|
||||||
@ -1668,7 +1679,7 @@ ossl_ssl_setup(VALUE self)
|
|||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_readable(fptr);
|
rb_io_check_readable(fptr);
|
||||||
rb_io_check_writable(fptr);
|
rb_io_check_writable(fptr);
|
||||||
if (!SSL_set_fd(ssl, TO_SOCKET(fptr->fd)))
|
if (!SSL_set_fd(ssl, TO_SOCKET(rb_io_descriptor(io))))
|
||||||
ossl_raise(eSSLError, "SSL_set_fd");
|
ossl_raise(eSSLError, "SSL_set_fd");
|
||||||
|
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
@ -1709,21 +1720,25 @@ no_exception_p(VALUE opts)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
io_wait_writable(rb_io_t *fptr)
|
io_wait_writable(VALUE io)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_RB_IO_MAYBE_WAIT
|
#ifdef HAVE_RB_IO_MAYBE_WAIT
|
||||||
rb_io_maybe_wait_writable(errno, fptr->self, RUBY_IO_TIMEOUT_DEFAULT);
|
rb_io_maybe_wait_writable(errno, io, RUBY_IO_TIMEOUT_DEFAULT);
|
||||||
#else
|
#else
|
||||||
|
rb_io_t *fptr;
|
||||||
|
GetOpenFile(io, fptr);
|
||||||
rb_io_wait_writable(fptr->fd);
|
rb_io_wait_writable(fptr->fd);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
io_wait_readable(rb_io_t *fptr)
|
io_wait_readable(VALUE io)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_RB_IO_MAYBE_WAIT
|
#ifdef HAVE_RB_IO_MAYBE_WAIT
|
||||||
rb_io_maybe_wait_readable(errno, fptr->self, RUBY_IO_TIMEOUT_DEFAULT);
|
rb_io_maybe_wait_readable(errno, io, RUBY_IO_TIMEOUT_DEFAULT);
|
||||||
#else
|
#else
|
||||||
|
rb_io_t *fptr;
|
||||||
|
GetOpenFile(io, fptr);
|
||||||
rb_io_wait_readable(fptr->fd);
|
rb_io_wait_readable(fptr->fd);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -1732,7 +1747,6 @@ static VALUE
|
|||||||
ossl_start_ssl(VALUE self, int (*func)(SSL *), const char *funcname, VALUE opts)
|
ossl_start_ssl(VALUE self, int (*func)(SSL *), const char *funcname, VALUE opts)
|
||||||
{
|
{
|
||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
rb_io_t *fptr;
|
|
||||||
int ret, ret2;
|
int ret, ret2;
|
||||||
VALUE cb_state;
|
VALUE cb_state;
|
||||||
int nonblock = opts != Qfalse;
|
int nonblock = opts != Qfalse;
|
||||||
@ -1744,7 +1758,7 @@ ossl_start_ssl(VALUE self, int (*func)(SSL *), const char *funcname, VALUE opts)
|
|||||||
|
|
||||||
GetSSL(self, ssl);
|
GetSSL(self, ssl);
|
||||||
|
|
||||||
GetOpenFile(rb_attr_get(self, id_i_io), fptr);
|
VALUE io = rb_attr_get(self, id_i_io);
|
||||||
for(;;){
|
for(;;){
|
||||||
ret = func(ssl);
|
ret = func(ssl);
|
||||||
|
|
||||||
@ -1762,12 +1776,12 @@ ossl_start_ssl(VALUE self, int (*func)(SSL *), const char *funcname, VALUE opts)
|
|||||||
case SSL_ERROR_WANT_WRITE:
|
case SSL_ERROR_WANT_WRITE:
|
||||||
if (no_exception_p(opts)) { return sym_wait_writable; }
|
if (no_exception_p(opts)) { return sym_wait_writable; }
|
||||||
write_would_block(nonblock);
|
write_would_block(nonblock);
|
||||||
io_wait_writable(fptr);
|
io_wait_writable(io);
|
||||||
continue;
|
continue;
|
||||||
case SSL_ERROR_WANT_READ:
|
case SSL_ERROR_WANT_READ:
|
||||||
if (no_exception_p(opts)) { return sym_wait_readable; }
|
if (no_exception_p(opts)) { return sym_wait_readable; }
|
||||||
read_would_block(nonblock);
|
read_would_block(nonblock);
|
||||||
io_wait_readable(fptr);
|
io_wait_readable(io);
|
||||||
continue;
|
continue;
|
||||||
case SSL_ERROR_SYSCALL:
|
case SSL_ERROR_SYSCALL:
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
@ -1906,8 +1920,7 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
|
|||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
int ilen;
|
int ilen;
|
||||||
VALUE len, str;
|
VALUE len, str;
|
||||||
rb_io_t *fptr;
|
VALUE opts = Qnil;
|
||||||
VALUE io, opts = Qnil;
|
|
||||||
|
|
||||||
if (nonblock) {
|
if (nonblock) {
|
||||||
rb_scan_args(argc, argv, "11:", &len, &str, &opts);
|
rb_scan_args(argc, argv, "11:", &len, &str, &opts);
|
||||||
@ -1932,8 +1945,7 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
|
|||||||
if (ilen == 0)
|
if (ilen == 0)
|
||||||
return str;
|
return str;
|
||||||
|
|
||||||
io = rb_attr_get(self, id_i_io);
|
VALUE io = rb_attr_get(self, id_i_io);
|
||||||
GetOpenFile(io, fptr);
|
|
||||||
|
|
||||||
rb_str_locktmp(str);
|
rb_str_locktmp(str);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -1953,7 +1965,7 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
|
|||||||
if (no_exception_p(opts)) { return sym_wait_writable; }
|
if (no_exception_p(opts)) { return sym_wait_writable; }
|
||||||
write_would_block(nonblock);
|
write_would_block(nonblock);
|
||||||
}
|
}
|
||||||
io_wait_writable(fptr);
|
io_wait_writable(io);
|
||||||
continue;
|
continue;
|
||||||
case SSL_ERROR_WANT_READ:
|
case SSL_ERROR_WANT_READ:
|
||||||
if (nonblock) {
|
if (nonblock) {
|
||||||
@ -1961,7 +1973,7 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
|
|||||||
if (no_exception_p(opts)) { return sym_wait_readable; }
|
if (no_exception_p(opts)) { return sym_wait_readable; }
|
||||||
read_would_block(nonblock);
|
read_would_block(nonblock);
|
||||||
}
|
}
|
||||||
io_wait_readable(fptr);
|
io_wait_readable(io);
|
||||||
continue;
|
continue;
|
||||||
case SSL_ERROR_SYSCALL:
|
case SSL_ERROR_SYSCALL:
|
||||||
if (!ERR_peek_error()) {
|
if (!ERR_peek_error()) {
|
||||||
@ -2027,14 +2039,14 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
|
|||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
int num, nonblock = opts != Qfalse;
|
int num, nonblock = opts != Qfalse;
|
||||||
VALUE tmp, io;
|
VALUE tmp;
|
||||||
|
|
||||||
GetSSL(self, ssl);
|
GetSSL(self, ssl);
|
||||||
if (!ssl_started(ssl))
|
if (!ssl_started(ssl))
|
||||||
rb_raise(eSSLError, "SSL session is not started yet");
|
rb_raise(eSSLError, "SSL session is not started yet");
|
||||||
|
|
||||||
tmp = rb_str_new_frozen(StringValue(str));
|
tmp = rb_str_new_frozen(StringValue(str));
|
||||||
io = rb_attr_get(self, id_i_io);
|
VALUE io = rb_attr_get(self, id_i_io);
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
|
|
||||||
/* SSL_write(3ssl) manpage states num == 0 is undefined */
|
/* SSL_write(3ssl) manpage states num == 0 is undefined */
|
||||||
@ -2050,12 +2062,12 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
|
|||||||
case SSL_ERROR_WANT_WRITE:
|
case SSL_ERROR_WANT_WRITE:
|
||||||
if (no_exception_p(opts)) { return sym_wait_writable; }
|
if (no_exception_p(opts)) { return sym_wait_writable; }
|
||||||
write_would_block(nonblock);
|
write_would_block(nonblock);
|
||||||
io_wait_writable(fptr);
|
io_wait_writable(io);
|
||||||
continue;
|
continue;
|
||||||
case SSL_ERROR_WANT_READ:
|
case SSL_ERROR_WANT_READ:
|
||||||
if (no_exception_p(opts)) { return sym_wait_readable; }
|
if (no_exception_p(opts)) { return sym_wait_readable; }
|
||||||
read_would_block(nonblock);
|
read_would_block(nonblock);
|
||||||
io_wait_readable(fptr);
|
io_wait_readable(io);
|
||||||
continue;
|
continue;
|
||||||
case SSL_ERROR_SYSCALL:
|
case SSL_ERROR_SYSCALL:
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user