Skip to content

Commit

Permalink
don't swallow connection errors, closes igrigorik#117
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed Jun 26, 2011
1 parent 0b902d4 commit c172b63
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
18 changes: 11 additions & 7 deletions examples/fibered-http.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$: << 'lib' << '../lib'

require 'eventmachine'
require 'em-http'
require 'fiber'
Expand All @@ -9,21 +11,23 @@ def async_fetch(url)
f = Fiber.current
http = EventMachine::HttpRequest.new(url).get :timeout => 10

if http.error.empty?
http.callback { f.resume(http) }
http.errback { f.resume(http) }
http.callback { f.resume(http) }
http.errback { f.resume(http) }

Fiber.yield

Fiber.yield
else
http
if http.error
p [:HTTP_ERROR, http.error]
end

http
end

EventMachine.run do
Fiber.new{

puts "Setting up HTTP request #1"
data = async_fetch('http://www.google.moo/')
data = async_fetch('http://0.0.0.0/')
puts "Fetched page #1: #{data.response_header.status}"

puts "Setting up HTTP request #2"
Expand Down
8 changes: 4 additions & 4 deletions lib/em-http/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def reset!
@state = :response_header

@response = ''
@error = ''
@error = nil
@content_decoder = nil
@content_charset = nil
end
Expand Down Expand Up @@ -78,7 +78,7 @@ def redirect?
@response_header.location && @req.follow_redirect?
end

def unbind(msg = '')
def unbind(reason = nil)
if finished?
if redirect?

Expand Down Expand Up @@ -106,11 +106,11 @@ def unbind(msg = '')
end

else
fail(self)
on_error(reason)
end
end

def on_error(msg = '')
def on_error(msg = nil)
@error = msg
fail(self)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/em-http/http_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def connection_completed
@parent.connection_completed
end

def unbind
@parent.unbind
def unbind(reason)
@parent.unbind(reason)
end
end

Expand Down Expand Up @@ -156,8 +156,8 @@ def redirect(client)
@pending.push client
end

def unbind(msg = '')
@clients.map { |c| c.unbind(msg) }
def unbind(reason)
@clients.map { |c| c.unbind(reason) }

if r = @pending.shift
@clients.push r
Expand Down

0 comments on commit c172b63

Please sign in to comment.