non-blocking connect (by phantomcircuit) #300

pull sipa wants to merge 1 commits into bitcoin:master from sipa:connecttimeout changing 5 files +93 −3
  1. sipa commented at 10:17 PM on June 5, 2011: member

    Use non-blocking connects, and a select() call to wait a predefined time (5s by default, but configurable with -timeout) for either success or failure. This allows much more connections to be tried per time unit.

    Based on a patch by phantomcircuit.

  2. TheBlueMatt commented at 11:55 PM on June 5, 2011: member

    As devrandom pointed out, tor latency could be much greater than 5s. Maybe add if (fProxy) timeout = 20s?

  3. sipa commented at 9:09 AM on June 6, 2011: member

    Maybe this can be done adaptively: start with a timeout=100ms, and each time N connection attempts have failed through time-out (and not enough connections are established), double the timeout.

  4. jrmithdobbs commented at 5:57 PM on June 6, 2011: contributor

    I think making it a command line override option would be a better way of handling it. In general you want to avoid connecting to other nodes where your network path is that latent. That way people who have known-latent paths can manually bump the timeout but it works as expected for most users.

  5. sipa commented at 6:59 PM on June 6, 2011: member

    @jrmithdobbs: good suggestion - implemented.

  6. gavinandresen commented at 6:29 PM on June 7, 2011: contributor

    I'd prefer removing the nConnectTimeout global variable and just calling GetArg("-timeout", 5000) in ConnectSocket.

  7. phantomcircuit commented at 4:32 PM on June 8, 2011: none

    My name is phantomcircuit and I approve this patch.

  8. sipa commented at 9:22 PM on June 8, 2011: member

    @gavinandresen: I disagree - I don't like global variables, but doing parsing of command-line options all over the place is even worse.

  9. jgarzik commented at 5:51 AM on June 10, 2011: contributor

    bleh, this is overkill.

    Use select with timeout -- as net.cpp already does -- and eliminate that polling loop.

    In all of linux/osx/winsock, you issue a non-blocking connect(2), and then select(2) the socket for writing.

  10. jgarzik commented at 4:59 PM on June 11, 2011: contributor

    ACK final result. Needs to be rebased though...

  11. gavinandresen commented at 7:35 PM on June 11, 2011: contributor

    ACK -- looks OK, but I haven't had time to compile and test.

  12. Faster timeout when connecting
    Use non-blocking connects, and a select() call to wait a predefined
    time (5s by default, but configurable with -timeout) for either
    success or failure. This allows much more connections to be tried
    per time unit.
    
    Based on a patch by phantomcircuit.
    76d660ebd3
  13. sipa commented at 10:44 PM on June 11, 2011: member

    Now using select() instead of looping. Tested on Linux and Windows.

  14. jgarzik referenced this in commit ce148944c7 on Jun 11, 2011
  15. jgarzik merged this on Jun 11, 2011
  16. jgarzik closed this on Jun 11, 2011

  17. ptschip referenced this in commit 52c6f7314a on Feb 17, 2017
  18. ptschip referenced this in commit da4619d419 on Apr 9, 2017
  19. destenson referenced this in commit 6cc2eb6617 on Nov 18, 2017
  20. classesjack referenced this in commit bbc7530e3f on Jan 2, 2018
  21. classesjack referenced this in commit 9c0fad58df on Jan 2, 2018
  22. classesjack referenced this in commit 896a33b228 on Jan 2, 2018
  23. attilaaf referenced this in commit d34312d728 on Jan 13, 2020
  24. Losangelosgenetics referenced this in commit 54bbdd3dde on Mar 12, 2020
  25. rajarshimaitra referenced this in commit 83f3c0b380 on Aug 5, 2021
  26. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-19 09:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me