1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Handle SSL eof and nonblocking

This commit is contained in:
Evan Phoenix 2012-08-22 22:34:10 -07:00
parent 17a058a158
commit f38678f2d7
3 changed files with 35 additions and 6 deletions

View file

@ -94,11 +94,10 @@ static VALUE eError;
void raise_error(SSL* ssl, int result) {
int error = SSL_get_error(ssl, result);
char buffer[256];
char* msg = ERR_error_string(error, NULL);
ERR_error_string_n(error, buffer, sizeof(buffer));
rb_raise(eError, "OpenSSL error: %s", buffer);
ERR_clear_error();
rb_raise(eError, "OpenSSL error: %s - %d", msg, error);
}
VALUE engine_read(VALUE self) {
@ -116,6 +115,10 @@ VALUE engine_read(VALUE self) {
if(SSL_want_read(conn->ssl)) return Qnil;
if(SSL_get_error(conn->ssl, bytes) == SSL_ERROR_ZERO_RETURN) {
rb_eof_error();
}
raise_error(conn->ssl, bytes);
}

View file

@ -99,7 +99,11 @@ module Puma
def try_to_finish
return read_body unless @read_header
data = @io.readpartial(CHUNK_SIZE)
begin
data = @io.read_nonblock(CHUNK_SIZE)
rescue Errno::EAGAIN
return false
end
if @buffer
@buffer << data
@ -136,7 +140,11 @@ module Puma
want = remain
end
chunk = @io.readpartial(want)
begin
chunk = @io.read_nonblock(want)
rescue Errno::EAGAIN
return false
end
# No chunk means a closed socket
unless chunk

View file

@ -26,6 +26,24 @@ module Puma::MiniSSL
end
end
def read_nonblock(size)
while true
output = @engine.read
return output if output
data = @socket.read_nonblock(size)
@engine.inject(data)
output = @engine.read
return output if output
while neg_data = @engine.extract
@socket.write neg_data
end
end
end
def write(data)
need = data.size