summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-06 13:59:31 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-06 13:59:31 +0000
commit70daacc533268d4bdf99ebfcc9f8a877453ab731 (patch)
tree4a1d58568a50137f7303bcb278877abe06b0de69 /ext/openssl
parenta971d184ce825d22b78ca4f08564bd09857cf9a9 (diff)
* 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
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/ossl_ssl.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index cff3258..d84c924 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:");
}