开发者

What is the connect timeout for a socket on linux

I have a programming running on linux ub开发者_高级运维untu 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜