Project

General

Profile

Feature #11124 ยป 0001-lib-use-monotonic-clock-for-timeouts.patch

normalperson (Eric Wong), 05/06/2015 10:34 PM

View differences:

lib/net/http.rb
1457 1457
      raise exception
1458 1458
    end
1459 1459

  
1460
    if defined?(Process::CLOCK_MONOTONIC)
1461
      def now
1462
        Process.clock_gettime(Process::CLOCK_MONOTONIC)
1463
      end
1464
    else
1465
      def now
1466
        Process.clock_gettime(Process::CLOCK_REALTIME)
1467
      end
1468
    end
1469

  
1460 1470
    def begin_transport(req)
1461 1471
      if @socket.closed?
1462 1472
        connect
1463
      elsif @last_communicated && @last_communicated + @keep_alive_timeout < Time.now
1473
      elsif @last_communicated && @last_communicated + @keep_alive_timeout < now
1464 1474
        D 'Conn close because of keep_alive_timeout'
1465 1475
        @socket.close
1466 1476
        connect
......
1484 1494
        @socket.close
1485 1495
      elsif keep_alive?(req, res)
1486 1496
        D 'Conn keep-alive'
1487
        @last_communicated = Time.now
1497
        @last_communicated = now
1488 1498
      else
1489 1499
        D 'Conn close'
1490 1500
        @socket.close
lib/resolv.rb
666 666
        @socks = nil
667 667
      end
668 668

  
669
      if defined?(Process::CLOCK_MONOTONIC)
670
        def now
671
          Process.clock_gettime(Process::CLOCK_MONOTONIC)
672
        end
673
      else
674
        def now
675
          Process.clock_gettime(Process::CLOCK_REALTIME)
676
        end
677
      end
678

  
669 679
      def request(sender, tout)
670
        start = Time.now
680
        start = now
671 681
        timelimit = start + tout
672 682
        begin
673 683
          sender.send
......
676 686
          raise ResolvTimeout
677 687
        end
678 688
        while true
679
          before_select = Time.now
689
          before_select = now
680 690
          timeout = timelimit - before_select
681 691
          if timeout <= 0
682 692
            raise ResolvTimeout
......
687 697
            select_result = IO.select(@socks, nil, nil, timeout)
688 698
          end
689 699
          if !select_result
690
            after_select = Time.now
700
            after_select = now
691 701
            next if after_select < timelimit
692 702
            raise ResolvTimeout
693 703
          end
694
-