mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/openssl/ossl_ssl.c (ossl_ssl_read): should check for error
status by SSL_get_error(). * ext/openssl/ossl_ssl.c (ossl_ssl_write): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6fe8d987ce
commit
932075e82e
2 changed files with 38 additions and 12 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Wed Dec 24 16:13:05 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
|
||||||
|
|
||||||
|
* ext/openssl/ossl_ssl.c (ossl_ssl_read): should check for error
|
||||||
|
status by SSL_get_error().
|
||||||
|
|
||||||
|
* ext/openssl/ossl_ssl.c (ossl_ssl_write): ditto.
|
||||||
|
|
||||||
Wed Dec 24 14:23:27 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Dec 24 14:23:27 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* ext/stringio/stringio.c (strio_read): clear the buffer argument
|
* ext/stringio/stringio.c (strio_read): clear the buffer argument
|
||||||
|
|
|
@ -496,11 +496,20 @@ ossl_ssl_read(VALUE self, VALUE len)
|
||||||
str = rb_str_new(0, ilen);
|
str = rb_str_new(0, ilen);
|
||||||
|
|
||||||
if (ssl) {
|
if (ssl) {
|
||||||
TRAP_BEG;
|
for (;;){
|
||||||
nread = SSL_read(ssl, RSTRING(str)->ptr, RSTRING(str)->len);
|
nread = SSL_read(ssl, RSTRING(str)->ptr, RSTRING(str)->len);
|
||||||
TRAP_END;
|
switch(SSL_get_error(ssl, nread)){
|
||||||
if (nread < 0) {
|
case SSL_ERROR_NONE:
|
||||||
ossl_raise(eSSLError, "SSL_read:");
|
goto end;
|
||||||
|
case SSL_ERROR_ZERO_RETURN:
|
||||||
|
ossl_raise(rb_eEOFError, "End of file reached");
|
||||||
|
case SSL_ERROR_WANT_WRITE:
|
||||||
|
case SSL_ERROR_WANT_READ:
|
||||||
|
rb_thread_schedule();
|
||||||
|
continue;
|
||||||
|
default:
|
||||||
|
ossl_raise(eSSLError, "SSL_read:");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -510,15 +519,15 @@ ossl_ssl_read(VALUE self, VALUE len)
|
||||||
TRAP_BEG;
|
TRAP_BEG;
|
||||||
nread = read(fileno(fptr->f), RSTRING(str)->ptr, RSTRING(str)->len);
|
nread = read(fileno(fptr->f), RSTRING(str)->ptr, RSTRING(str)->len);
|
||||||
TRAP_END;
|
TRAP_END;
|
||||||
|
if (nread == 0) {
|
||||||
|
ossl_raise(rb_eEOFError, "End of file reached");
|
||||||
|
}
|
||||||
if(nread < 0) {
|
if(nread < 0) {
|
||||||
ossl_raise(eSSLError, "read:%s", strerror(errno));
|
ossl_raise(eSSLError, "read:%s", strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nread == 0) {
|
end:
|
||||||
ossl_raise(rb_eEOFError, "End of file reached");
|
|
||||||
}
|
|
||||||
|
|
||||||
RSTRING(str)->len = nread;
|
RSTRING(str)->len = nread;
|
||||||
RSTRING(str)->ptr[nread] = 0;
|
RSTRING(str)->ptr[nread] = 0;
|
||||||
OBJ_TAINT(str);
|
OBJ_TAINT(str);
|
||||||
|
@ -538,9 +547,18 @@ ossl_ssl_write(VALUE self, VALUE str)
|
||||||
StringValue(str);
|
StringValue(str);
|
||||||
|
|
||||||
if (ssl) {
|
if (ssl) {
|
||||||
nwrite = SSL_write(ssl, RSTRING(str)->ptr, RSTRING(str)->len);
|
for (;;){
|
||||||
if (nwrite <= 0) {
|
nwrite = SSL_write(ssl, RSTRING(str)->ptr, RSTRING(str)->len);
|
||||||
ossl_raise(eSSLError, "SSL_write:");
|
switch(SSL_get_error(ssl, nwrite)){
|
||||||
|
case SSL_ERROR_NONE:
|
||||||
|
goto end;
|
||||||
|
case SSL_ERROR_WANT_WRITE:
|
||||||
|
case SSL_ERROR_WANT_READ:
|
||||||
|
rb_thread_schedule();
|
||||||
|
continue;
|
||||||
|
default:
|
||||||
|
ossl_raise(eSSLError, "SSL_write:");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -554,6 +572,7 @@ ossl_ssl_write(VALUE self, VALUE str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
return INT2NUM(nwrite);
|
return INT2NUM(nwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue