开发者

What is the connect timeout for a socket on linux

开发者 https://www.devze.com 2023-01-01 19:56 出处:网络
I have a programming running on linux ub开发者_高级运维untu which tries to connect to a server port using TCP.

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

精彩评论

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

关注公众号