@@ -1653,6 +1653,17 @@ ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)
1653
1653
return self ;
1654
1654
}
1655
1655
1656
+ #ifndef HAVE_RB_IO_DESCRIPTOR
1657
+ static int
1658
+ io_descriptor_fallback (VALUE io )
1659
+ {
1660
+ rb_io_t * fptr ;
1661
+ GetOpenFile (io , fptr );
1662
+ return fptr -> fd ;
1663
+ }
1664
+ #define rb_io_descriptor io_descriptor_fallback
1665
+ #endif
1666
+
1656
1667
static VALUE
1657
1668
ossl_ssl_setup (VALUE self )
1658
1669
{
@@ -1668,8 +1679,8 @@ ossl_ssl_setup(VALUE self)
1668
1679
GetOpenFile (io , fptr );
1669
1680
rb_io_check_readable (fptr );
1670
1681
rb_io_check_writable (fptr );
1671
- if (!SSL_set_fd (ssl , TO_SOCKET (fptr -> fd )))
1672
- ossl_raise (eSSLError , "SSL_set_fd" );
1682
+ if (!SSL_set_fd (ssl , TO_SOCKET (rb_io_descriptor ( io ) )))
1683
+ ossl_raise (eSSLError , "SSL_set_fd" );
1673
1684
1674
1685
return Qtrue ;
1675
1686
}
@@ -1709,21 +1720,25 @@ no_exception_p(VALUE opts)
1709
1720
#endif
1710
1721
1711
1722
static void
1712
- io_wait_writable (rb_io_t * fptr )
1723
+ io_wait_writable (VALUE io )
1713
1724
{
1714
1725
#ifdef HAVE_RB_IO_MAYBE_WAIT
1715
- rb_io_maybe_wait_writable (errno , fptr -> self , RUBY_IO_TIMEOUT_DEFAULT );
1726
+ rb_io_maybe_wait_writable (errno , io , RUBY_IO_TIMEOUT_DEFAULT );
1716
1727
#else
1728
+ rb_io_t * fptr ;
1729
+ GetOpenFile (io , fptr );
1717
1730
rb_io_wait_writable (fptr -> fd );
1718
1731
#endif
1719
1732
}
1720
1733
1721
1734
static void
1722
- io_wait_readable (rb_io_t * fptr )
1735
+ io_wait_readable (VALUE io )
1723
1736
{
1724
1737
#ifdef HAVE_RB_IO_MAYBE_WAIT
1725
- rb_io_maybe_wait_readable (errno , fptr -> self , RUBY_IO_TIMEOUT_DEFAULT );
1738
+ rb_io_maybe_wait_readable (errno , io , RUBY_IO_TIMEOUT_DEFAULT );
1726
1739
#else
1740
+ rb_io_t * fptr ;
1741
+ GetOpenFile (io , fptr );
1727
1742
rb_io_wait_readable (fptr -> fd );
1728
1743
#endif
1729
1744
}
@@ -1732,7 +1747,6 @@ static VALUE
1732
1747
ossl_start_ssl (VALUE self , int (* func )(SSL * ), const char * funcname , VALUE opts )
1733
1748
{
1734
1749
SSL * ssl ;
1735
- rb_io_t * fptr ;
1736
1750
int ret , ret2 ;
1737
1751
VALUE cb_state ;
1738
1752
int nonblock = opts != Qfalse ;
@@ -1744,7 +1758,7 @@ ossl_start_ssl(VALUE self, int (*func)(SSL *), const char *funcname, VALUE opts)
1744
1758
1745
1759
GetSSL (self , ssl );
1746
1760
1747
- GetOpenFile ( rb_attr_get (self , id_i_io ), fptr );
1761
+ VALUE io = rb_attr_get (self , id_i_io );
1748
1762
for (;;){
1749
1763
ret = func (ssl );
1750
1764
@@ -1762,12 +1776,12 @@ ossl_start_ssl(VALUE self, int (*func)(SSL *), const char *funcname, VALUE opts)
1762
1776
case SSL_ERROR_WANT_WRITE :
1763
1777
if (no_exception_p (opts )) { return sym_wait_writable ; }
1764
1778
write_would_block (nonblock );
1765
- io_wait_writable (fptr );
1779
+ io_wait_writable (io );
1766
1780
continue ;
1767
1781
case SSL_ERROR_WANT_READ :
1768
1782
if (no_exception_p (opts )) { return sym_wait_readable ; }
1769
1783
read_would_block (nonblock );
1770
- io_wait_readable (fptr );
1784
+ io_wait_readable (io );
1771
1785
continue ;
1772
1786
case SSL_ERROR_SYSCALL :
1773
1787
#ifdef __APPLE__
@@ -1906,8 +1920,7 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
1906
1920
SSL * ssl ;
1907
1921
int ilen ;
1908
1922
VALUE len , str ;
1909
- rb_io_t * fptr ;
1910
- VALUE io , opts = Qnil ;
1923
+ VALUE opts = Qnil ;
1911
1924
1912
1925
if (nonblock ) {
1913
1926
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)
1932
1945
if (ilen == 0 )
1933
1946
return str ;
1934
1947
1935
- io = rb_attr_get (self , id_i_io );
1936
- GetOpenFile (io , fptr );
1948
+ VALUE io = rb_attr_get (self , id_i_io );
1937
1949
1938
1950
rb_str_locktmp (str );
1939
1951
for (;;) {
@@ -1953,15 +1965,15 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
1953
1965
if (no_exception_p (opts )) { return sym_wait_writable ; }
1954
1966
write_would_block (nonblock );
1955
1967
}
1956
- io_wait_writable (fptr );
1968
+ io_wait_writable (io );
1957
1969
continue ;
1958
1970
case SSL_ERROR_WANT_READ :
1959
1971
if (nonblock ) {
1960
1972
rb_str_unlocktmp (str );
1961
1973
if (no_exception_p (opts )) { return sym_wait_readable ; }
1962
1974
read_would_block (nonblock );
1963
1975
}
1964
- io_wait_readable (fptr );
1976
+ io_wait_readable (io );
1965
1977
continue ;
1966
1978
case SSL_ERROR_SYSCALL :
1967
1979
if (!ERR_peek_error ()) {
@@ -2027,14 +2039,14 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
2027
2039
SSL * ssl ;
2028
2040
rb_io_t * fptr ;
2029
2041
int num , nonblock = opts != Qfalse ;
2030
- VALUE tmp , io ;
2042
+ VALUE tmp ;
2031
2043
2032
2044
GetSSL (self , ssl );
2033
2045
if (!ssl_started (ssl ))
2034
2046
rb_raise (eSSLError , "SSL session is not started yet" );
2035
2047
2036
2048
tmp = rb_str_new_frozen (StringValue (str ));
2037
- io = rb_attr_get (self , id_i_io );
2049
+ VALUE io = rb_attr_get (self , id_i_io );
2038
2050
GetOpenFile (io , fptr );
2039
2051
2040
2052
/* SSL_write(3ssl) manpage states num == 0 is undefined */
@@ -2050,12 +2062,12 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
2050
2062
case SSL_ERROR_WANT_WRITE :
2051
2063
if (no_exception_p (opts )) { return sym_wait_writable ; }
2052
2064
write_would_block (nonblock );
2053
- io_wait_writable (fptr );
2065
+ io_wait_writable (io );
2054
2066
continue ;
2055
2067
case SSL_ERROR_WANT_READ :
2056
2068
if (no_exception_p (opts )) { return sym_wait_readable ; }
2057
2069
read_would_block (nonblock );
2058
- io_wait_readable (fptr );
2070
+ io_wait_readable (io );
2059
2071
continue ;
2060
2072
case SSL_ERROR_SYSCALL :
2061
2073
#ifdef __APPLE__
0 commit comments