summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--ext/openssl/ossl_ssl.c31
2 files changed, 37 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index c5ad5eb..1a8bb15 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 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:");
}