Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

-[NSFileHandle availableData] is not quite the same as IO#readpartial

git-svn-id: http://svn.macosforge.org/repository/ruby/ControlTower/trunk@4277 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit cf2ddee73341a6bbfd24889ae9616b0e6b2e92a0 1 parent b569d26
@jballanc jballanc authored
Showing with 6 additions and 3 deletions.
  1. +6 −3 lib/control_tower/rack_socket.rb
View
9 lib/control_tower/rack_socket.rb
@@ -85,18 +85,21 @@ def parse!(connection, env)
parser = ::CTParser.new
data = NSMutableData.alloc.init
parsing_headers = true # Parse headers first
+ nread = 0
content_length = 0
content_uploaded = 0
connection_handle = NSFileHandle.alloc.initWithFileDescriptor(connection.fileno)
$stdout.puts "Started parsing at #{Time.now.to_f}"
while (parsing_headers || content_uploaded < content_length) do
- # Read the availableData on the socket and rescue any errors:
+ # Read the availableData on the socket and give up if there's nothing
incoming_bytes = connection_handle.availableData
+ return nil if incoming_bytes.length == 0
# Until the headers are done being parsed, we'll parse them
if parsing_headers
data.appendData(incoming_bytes)
+ $stdout.puts "Calling parser with #{data.length} bytes starting at #{nread}"
nread = parser.parseData(data, forEnvironment: env, startingAt: nread)
if parser.finished
$stdout.puts "Finished parsing headers at #{Time.now.to_f}"
@@ -122,9 +125,9 @@ def parse!(connection, env)
env['rack.input'].each { |upload_data| body << upload_data.to_str }
env['rack.input'] = body
end
- # Returning what we've got...
- return env
end
+ # Returning what we've got...
+ return env
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.