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

Cleanup the JRuby specific fix

This commit is contained in:
Evan Phoenix 2012-08-10 19:35:47 -07:00
parent 870767a246
commit 652cf29391
3 changed files with 58 additions and 35 deletions

View file

@ -4,6 +4,7 @@ require 'uri'
require 'puma/server'
require 'puma/const'
require 'puma/configuration'
require 'puma/detect'
require 'rack/commonlogger'
require 'rack/utils'
@ -12,8 +13,6 @@ module Puma
# Handles invoke a Puma::Server in a command line style.
#
class CLI
IS_JRUBY = defined?(JRUBY_VERSION)
# Create a new CLI object using +argv+ as the command line
# arguments.
#

View file

@ -1,8 +1,20 @@
class IO
# We need to use this for a jruby work around on both 1.8 and 1.9.
# So this either creates the constant (on 1.8), or harmlessly
# reopens it (on 1.9).
module WaitReadable
end
end
require 'puma/detect'
if Puma::IS_JRUBY
# We have to work around some OpenSSL buffer/io-readiness bugs
# so we pull it in regardless of if the user is binding
# to an SSL socket
require 'openssl'
end
module Puma
class Client
include Puma::Const
@ -132,46 +144,54 @@ module Puma
false
end
def jruby_start_try_to_finish
return read_body unless @read_header
if IS_JRUBY
def jruby_start_try_to_finish
return read_body unless @read_header
begin
data = @io.sysread_nonblock(CHUNK_SIZE)
rescue OpenSSL::SSL::SSLError => e
return false if e.kind_of? IO::WaitReadable
raise e
begin
data = @io.sysread_nonblock(CHUNK_SIZE)
rescue OpenSSL::SSL::SSLError => e
return false if e.kind_of? IO::WaitReadable
raise e
end
if @buffer
@buffer << data
else
@buffer = data
end
@parsed_bytes = @parser.execute(@env, @buffer, @parsed_bytes)
if @parser.finished?
return setup_body
elsif @parsed_bytes >= MAX_HEADER
raise HttpParserError,
"HEADER is longer than allowed, aborting client early."
end
false
end
if @buffer
@buffer << data
else
@buffer = data
def eagerly_finish
return true if @ready
if @io.kind_of? OpenSSL::SSL::SSLSocket
return true if jruby_start_try_to_finish
end
return false unless IO.select([@to_io], nil, nil, 0)
try_to_finish
end
@parsed_bytes = @parser.execute(@env, @buffer, @parsed_bytes)
else
if @parser.finished?
return setup_body
elsif @parsed_bytes >= MAX_HEADER
raise HttpParserError,
"HEADER is longer than allowed, aborting client early."
def eagerly_finish
return true if @ready
return false unless IO.select([@to_io], nil, nil, 0)
try_to_finish
end
false
end
def eagerly_finish
return true if @ready
if defined?(JRUBY_VERSION) and
defined?(OpenSSL::SSL::SSLSocket) and
@io.kind_of? OpenSSL::SSL::SSLSocket
return true if jruby_start_try_to_finish
end
return false unless IO.select([@to_io], nil, nil, 0)
try_to_finish
end
end # IS_JRUBY
def read_body
# Read an odd sized chunk so we can read even sized ones

4
lib/puma/detect.rb Normal file
View file

@ -0,0 +1,4 @@
module Puma
IS_JRUBY = defined?(JRUBY_VERSION)
end