3

I create a non-blocking socket, and then use the epoll to manange the socket. I do not set a timeout on epoll_wait. But I find that the epoll returned in 5s to 10s, then I check with the getsockopt on SO_ERROR, the connect find to be timed out. Why time out in so short time?

I try to use tools to cap the TCP packages. The scenario is like this:

When my client send a SYN in order to connect to the server. But the server cannot send back the ACK in 5s to 10s. Then the epoll_wait return. and check with the SO_ERROR. I get a EIMTEDOUT.

I just cannot understand why the timeout time is so short in 5s to 10s. Is the problem of my client or is the epoll?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
hyman
  • 43
  • 1
  • 5
  • +1 - 5-10 secs is indeed very short for a connect timeout. If the link contained a dial-up modem, for example, the connect would always fail with such a short timeout. I would like to know why this happens as well. – Martin James Dec 26 '11 at 13:59
  • I don't knwo why. I just use the libev. the description above is exactly what the libev do in C++. I just find the libev return ETIMEDOUT in so short time. – hyman Dec 26 '11 at 14:08

1 Answers1

1

I posted a similar question recently See the accepted answer which explains how the TCP connect timeout value is calculated by the linux kernel.. If you happen to have the client/server on the same machine its quite likely to have shorter timeout values. If you expect server to take longer than that to accept a connection you might want to set the timeout value yourself explicitly.

Community
  • 1
  • 1
Manohar
  • 3,865
  • 11
  • 41
  • 56
  • Thanks. I got over it. As your question, the TCP timeout value is calculated dynamically by the kernel. – hyman Feb 07 '12 at 06:48