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:
parent
17a058a158
commit
f38678f2d7
3 changed files with 35 additions and 6 deletions
|
@ -94,11 +94,10 @@ static VALUE eError;
|
||||||
|
|
||||||
void raise_error(SSL* ssl, int result) {
|
void raise_error(SSL* ssl, int result) {
|
||||||
int error = SSL_get_error(ssl, 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));
|
ERR_clear_error();
|
||||||
|
rb_raise(eError, "OpenSSL error: %s - %d", msg, error);
|
||||||
rb_raise(eError, "OpenSSL error: %s", buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE engine_read(VALUE self) {
|
VALUE engine_read(VALUE self) {
|
||||||
|
@ -116,6 +115,10 @@ VALUE engine_read(VALUE self) {
|
||||||
|
|
||||||
if(SSL_want_read(conn->ssl)) return Qnil;
|
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);
|
raise_error(conn->ssl, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,11 @@ module Puma
|
||||||
def try_to_finish
|
def try_to_finish
|
||||||
return read_body unless @read_header
|
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
|
if @buffer
|
||||||
@buffer << data
|
@buffer << data
|
||||||
|
@ -136,7 +140,11 @@ module Puma
|
||||||
want = remain
|
want = remain
|
||||||
end
|
end
|
||||||
|
|
||||||
chunk = @io.readpartial(want)
|
begin
|
||||||
|
chunk = @io.read_nonblock(want)
|
||||||
|
rescue Errno::EAGAIN
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
# No chunk means a closed socket
|
# No chunk means a closed socket
|
||||||
unless chunk
|
unless chunk
|
||||||
|
|
|
@ -26,6 +26,24 @@ module Puma::MiniSSL
|
||||||
end
|
end
|
||||||
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)
|
def write(data)
|
||||||
need = data.size
|
need = data.size
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue