diff options
author | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-06 13:59:31 +0000 |
---|---|---|
committer | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-06 13:59:31 +0000 |
commit | 70daacc533268d4bdf99ebfcc9f8a877453ab731 (patch) | |
tree | 4a1d58568a50137f7303bcb278877abe06b0de69 | |
parent | a971d184ce825d22b78ca4f08564bd09857cf9a9 (diff) | |
download | ruby-70daacc533268d4bdf99ebfcc9f8a877453ab731.tar.gz |
* ext/openssl/ossl_ssl.c (ossl_start_ssl): new function to wrap
SSL_connect and SSL_accept; if SSL_connect (or SSL_accept) returned
but not finished the handshake process, we should retry it.
* ext/openssl/ossl_ssl.c (ossl_ssl_connect): call ossl_start_ssl.
* ext/openssl/ossl_ssl.c (ossl_ssl_accept): ditto.
* ext/openssl/ossl_ssl.c (ossl_ssl_read): allow signal traps.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | ext/openssl/ossl_ssl.c | 31 |
2 files changed, 37 insertions, 6 deletions
@@ -1,3 +1,15 @@ +Sat Dec 6 22:58:03 2003 GOTOU Yuuzou <gotoyuzo@notwork.org> + + * ext/openssl/ossl_ssl.c (ossl_start_ssl): new function to wrap + SSL_connect and SSL_accept; if SSL_connect (or SSL_accept) returned + but not finished the handshake process, we should retry it. + + * ext/openssl/ossl_ssl.c (ossl_ssl_connect): call ossl_start_ssl. + + * ext/openssl/ossl_ssl.c (ossl_ssl_accept): ditto. + + * ext/openssl/ossl_ssl.c (ossl_ssl_read): allow signal traps. + Sat Dec 6 21:45:10 2003 WATANABE Hirofumi <eban@ruby-lang.org> * io.c (flush_before_seek): flush before seek on any platform. diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index cff32582ed..d84c92498f 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -435,6 +435,27 @@ ossl_ssl_setup(VALUE self) return Qtrue; } +static void +ossl_start_ssl(SSL *ssl, int (*func)()) +{ + int ret; + + for(;;){ + if((ret = func(ssl)) > 0) break; + switch(SSL_get_error(ssl, ret)){ + case SSL_ERROR_NONE: + break; + case SSL_ERROR_WANT_WRITE: + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_X509_LOOKUP: + rb_thread_schedule(); + continue; + default: + ossl_raise(eSSLError, "SSL_accept:"); + } + } +} + static VALUE ossl_ssl_connect(VALUE self) { @@ -445,9 +466,7 @@ ossl_ssl_connect(VALUE self) Data_Get_Struct(self, SSL, ssl); cb = ossl_sslctx_get_verify_cb(ossl_ssl_get_ctx(self)); SSL_set_ex_data(ssl, ossl_ssl_ex_vcb_idx, (void *)cb); - if (SSL_connect(ssl) <= 0) { - ossl_raise(eSSLError, "SSL_connect:"); - } + ossl_start_ssl(ssl, SSL_connect); return self; } @@ -462,9 +481,7 @@ ossl_ssl_accept(VALUE self) Data_Get_Struct(self, SSL, ssl); cb = ossl_sslctx_get_verify_cb(ossl_ssl_get_ctx(self)); SSL_set_ex_data(ssl, ossl_ssl_ex_vcb_idx, (void *)cb); - if (SSL_accept(ssl) <= 0) { - ossl_raise(eSSLError, "SSL_accept:"); - } + ossl_start_ssl(ssl, SSL_accept); return self; } @@ -482,7 +499,9 @@ ossl_ssl_read(VALUE self, VALUE len) str = rb_str_new(0, ilen); if (ssl) { + TRAP_BEG; nread = SSL_read(ssl, RSTRING(str)->ptr, RSTRING(str)->len); + TRAP_END; if (nread < 0) { ossl_raise(eSSLError, "SSL_read:"); } |