Skip to content

Commit

Permalink
isolating read/write ssl ops
Browse files Browse the repository at this point in the history
  • Loading branch information
HoneyryderChuck committed Mar 26, 2024
1 parent a8caa63 commit 62fd3e4
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions ext/openssl/ossl_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,22 @@ no_exception_p(VALUE opts)
#endif


int ossl_ssl_connect_impl(SSL *ssl)
{
return SSL_connect(ssl);
}

int ossl_ssl_read_impl(SSL *ssl, VALUE str, int ilen)
{
return SSL_read(ssl, RSTRING_PTR(str), ilen);
}

int ossl_ssl_write_impl(SSL *ssl, VALUE tmp, int num)
{
return SSL_write(ssl, RSTRING_PTR(tmp), num);
}


static void
io_wait_writable(VALUE io)
{
Expand Down Expand Up @@ -1848,7 +1864,7 @@ ossl_ssl_connect(VALUE self)
{
ossl_ssl_setup(self);

return ossl_start_ssl(self, SSL_connect, "SSL_connect", Qfalse);
return ossl_start_ssl(self, ossl_ssl_connect_impl, "SSL_connect", Qfalse);
}

/*
Expand Down Expand Up @@ -1881,7 +1897,7 @@ ossl_ssl_connect_nonblock(int argc, VALUE *argv, VALUE self)

ossl_ssl_setup(self);

return ossl_start_ssl(self, SSL_connect, "SSL_connect", opts);
return ossl_start_ssl(self, ossl_ssl_connect_impl, "SSL_connect", opts);
}

/*
Expand Down Expand Up @@ -1966,7 +1982,7 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)

rb_str_locktmp(str);
for (;;) {
int nread = SSL_read(ssl, RSTRING_PTR(str), ilen);
int nread = ossl_ssl_read_impl(ssl, str, ilen);
switch (ssl_get_error(ssl, nread)) {
case SSL_ERROR_NONE:
rb_str_unlocktmp(str);
Expand Down Expand Up @@ -2072,7 +2088,7 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
return INT2FIX(0);

for (;;) {
int nwritten = SSL_write(ssl, RSTRING_PTR(tmp), num);
int nwritten = ossl_ssl_write_impl(ssl, tmp, num);
switch (ssl_get_error(ssl, nwritten)) {
case SSL_ERROR_NONE:
return INT2NUM(nwritten);
Expand Down

0 comments on commit 62fd3e4

Please sign in to comment.