Changeset 607

Show
Ignore:
Timestamp:
12/05/07 10:10:44 (1 year ago)
Author:
blackhedd
Message:

fixed bug: connection completed was getting called even with failed TCP connect attempts.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • version_0/lib/pr_eventmachine.rb

    r606 r607  
    178178 
    179179    # #get_outbound_data_size 
     180    # 
    180181    def get_outbound_data_size sig 
    181182      r = Reactor.instance.get_selectable( sig ) or raise "unknown get_outbound_data_size target" 
     
    183184    end 
    184185 
     186    # #set_comm_inactivity_timeout 
     187    # 
     188    def set_comm_inactivity_timeout sig, tm 
     189      r = Reactor.instance.get_selectable( sig ) or raise "unknown set_comm_inactivity_timeout target" 
     190      p "?????????????" # TODO, IMPLEMENT THIS. 
     191    end 
    185192  end 
    186193 
     
    479486      rescue Errno::EAGAIN 
    480487        # no-op 
    481       rescue Errno::ECONNRESET, EOFError 
     488      rescue Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError 
    482489        @close_scheduled = true 
    483490        EventMachine::event_callback uuid, ConnectionUnbound, nil 
     
    594601      if @pending 
    595602        @pending = false 
    596         EventMachine::event_callback uuid, ConnectionCompleted, "" 
     603        if 0 == io.getsockopt(Socket::SOL_SOCKET, Socket::SO_ERROR).unpack("i").first 
     604          EventMachine::event_callback uuid, ConnectionCompleted, "" 
     605        end 
    597606      else 
    598607        super 
  • version_0/tests/test_pure.rb

    r605 r607  
    7171 
    7272 
     73 
     74  # Under some circumstances, the pure Ruby library would emit an Errno::ECONNREFUSED 
     75  # exception on certain kinds of TCP connect-errors. 
     76  # It's always been something of an open question whether EM should throw an exception 
     77  # in these cases but the defined answer has always been to catch it the unbind method. 
     78  # With a connect failure, the latter will always fire, but connection_completed will 
     79  # never fire. So even though the point is arguable, it's incorrect for the pure Ruby 
     80  # version to throw an exception. 
     81  module TestConnrefused 
     82    def unbind 
     83      EM.stop 
     84    end 
     85    def connection_completed 
     86      raise "should never get here" 
     87    end 
     88  end 
     89  def test_connrefused 
     90    EM.run { 
     91      EM.connect "0.0.0.0", 60001, TestConnrefused 
     92    } 
     93  end 
     94 
     95 
     96  # Make sure connection_completed gets called as expected with TCP clients. This is the 
     97  # opposite of test_connrefused. 
     98  # If the test fails, it will hang because EM.stop never gets called. 
     99  # 
     100  module TestConnaccepted 
     101    def connection_completed 
     102      EM.stop 
     103    end 
     104  end 
     105  def test_connaccepted 
     106    timeout = false 
     107    EM.run { 
     108      EM.start_server "0.0.0.0", 60002 
     109      EM.connect "0.0.0.0", 60002, TestConnaccepted 
     110      EM::Timer.new(1) {timeout = true; EM.stop} 
     111    } 
     112    assert_equal( false, timeout ) 
     113  end 
     114 
    73115end