michael
michael

Reputation: 110570

What is the connect timeout for a socket on linux

I have a programming running on linux ubuntu which tries to connect to a server port using TCP. Can you please tell me how can I find out that is timeout value for a client socket connecting to a server socket for ubuntu?

Thank you.

Upvotes: 0

Views: 1914

Answers (2)

Platypus
Platypus

Reputation: 204

The best, portable solution is to use your own timeout to be sure you can rely on a known value :

1) before connect()ing, set the client socket to be non-blocking. Use ioctl() and the FIONBIO flag or fcntl() and O_NONBLOCK flags. Under Win32, use ioctlsocket() and FIONBIO flag.

2) connect() to the remote peer : if connect() succeed, all right, you are connected.

3) However if connect() returns -1 and set errno to EINPROGRESS (WSAEWOULDBLOCK under Win32), just select() the socket descriptor for writing with your own timeout.

Upvotes: 2

Jim Dennis
Jim Dennis

Reputation: 17500

I'd start by looking at the getsockopt(3) man page (SO_RCVTIMEO). However I'm sure there's more to your question than that.

Upvotes: 1

Related Questions