Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup the JRuby specific fix

  • Loading branch information...
commit 652cf29391ba4bcc100458d0e0d0ff2e384e9ea4 1 parent 870767a
@evanphx evanphx authored
Showing with 55 additions and 32 deletions.
  1. +1 −2  lib/puma/cli.rb
  2. +50 −30 lib/puma/client.rb
  3. +4 −0 lib/puma/detect.rb
View
3  lib/puma/cli.rb
@@ -4,6 +4,7 @@
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
80 lib/puma/client.rb
@@ -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 @@ def try_to_finish
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
- end
+ 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
+ if @buffer
+ @buffer << data
+ else
+ @buffer = data
+ end
- @parsed_bytes = @parser.execute(@env, @buffer, @parsed_bytes)
+ @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."
+ if @parser.finished?
+ return setup_body
+ elsif @parsed_bytes >= MAX_HEADER
+ raise HttpParserError,
+ "HEADER is longer than allowed, aborting client early."
+ end
+
+ false
end
- false
- end
+ def eagerly_finish
+ return true if @ready
- def eagerly_finish
- return true if @ready
+ if @io.kind_of? OpenSSL::SSL::SSLSocket
+ return true if jruby_start_try_to_finish
+ end
- if defined?(JRUBY_VERSION) and
- defined?(OpenSSL::SSL::SSLSocket) and
- @io.kind_of? OpenSSL::SSL::SSLSocket
- return true if jruby_start_try_to_finish
+ return false unless IO.select([@to_io], nil, nil, 0)
+ try_to_finish
end
- return false unless IO.select([@to_io], nil, nil, 0)
- try_to_finish
- end
+ else
+
+ def eagerly_finish
+ return true if @ready
+ 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
View
4 lib/puma/detect.rb
@@ -0,0 +1,4 @@
+module Puma
+ IS_JRUBY = defined?(JRUBY_VERSION)
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.