Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minissl read_nonblock fix #1444

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 18 additions & 12 deletions lib/puma/minissl.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
begin
require 'io/wait'
rescue LoadError
end

module Puma
module MiniSSL
class Socket
Expand Down Expand Up @@ -43,19 +48,20 @@ def read_nonblock(size, *_)
output = engine_read_all
return output if output

if /mswin|mingw/ !~ RUBY_PLATFORM
data = @socket.read_nonblock(size)
else
begin
data = @socket.read_nonblock(size)
rescue IO::WaitReadable
IO.select([@socket.to_io])
retry
rescue IO::WaitWritable
IO.select(nil, [@socket.to_io])
retry
begin
data = @socket.read_nonblock(size, exception: false)
if data == :wait_readable || data == :wait_writable
if @socket.to_io.respond_to?(data)
@socket.to_io.__send__(data)
elsif data == :wait_readable
IO.select([@socket.to_io])
else
IO.select(nil, [@socket.to_io])
end
else
break
end
end
end while true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason not to use loop do ... end for this loop?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It'd introduce a block, making data block-local.)


@engine.inject(data)
output = engine_read_all
Expand Down