Skip to content

Commit

Permalink
-[NSFileHandle availableData] is not quite the same as IO#readpartial
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/ControlTower/trunk@4277 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
jballanc committed Jun 25, 2010
1 parent b569d26 commit cf2ddee
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/control_tower/rack_socket.rb
Expand Up @@ -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}"
Expand All @@ -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

0 comments on commit cf2ddee

Please sign in to comment.