1

connect is failing with WSAETIMEDOUT. That's fine but is there anyway to make the timeout period shorter? Maybe something like 2-3 seconds? Currently it seems to be something higher like 10 seconds.

OS is Windows, using Winsock with C++

Josh
  • 6,046
  • 11
  • 52
  • 83
  • possible duplicate of [WINSOCK - Setting a timeout for a connection attempt on a non existing IP?](http://stackoverflow.com/questions/6199122/winsock-setting-a-timeout-for-a-connection-attempt-on-a-non-existing-ip) – Nick Apr 16 '12 at 15:27

2 Answers2

1

Put the socket into non-blocking mode before calling connect(). When it returns with a WSAEWOULDBLOCK error, call select() with whatever timeout interval you want. If select() reports the socket becomes writable, the connection was successful. If select() reports a timeout instead, close the socket.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • On my PC default (blocking) connect timeout is 3+6+12+24=45 seconds. Is it safe to close socket in non-blocking mode before this interval expires ? – truthseeker Aug 12 '15 at 10:52
  • @truthseeker: The interval for the default connect timeout on any given PC is not guaranteed. And yes, you can close the socket before it times out. – Remy Lebeau Aug 12 '15 at 17:10
0

This has been asked before: WINSOCK - Setting a timeout for a connection attempt on a non existing IP?

No, it's handled by the IP stack. You'll have to start a timer and kill the connection if you need to change this functionality.

Community
  • 1
  • 1
Nick
  • 25,026
  • 7
  • 51
  • 83