[英]How to set a timeout to “connect()” function on C sockets?
I have to connect a several ips on same subnet concurrently. 我必须同时在同一子网上连接几个IP。 Buy its takes me too long! 买它花了我太多时间! (almost 25 seconds) to wait untill the all " connect()
" functions done! (将近25秒)等待所有“ connect()
”函数完成!
How can I oprtimize this behavior in winsock, CPP? 如何在Winsock,CPP中优化这种行为? I find about somthing called " select
" but aperrently it works only for linux so.. 我发现一种叫做“ select
”的东西,但目前看来它仅适用于linux。
select()
works on Unix, Linux, Windows, Netware, and every other platform I have ever tested it on. select()
可在Unix,Linux,Windows,Netware以及我曾经在其上进行过测试的所有其他平台上使用。
connect()
. 调用connect()
。 It will fail with EAGAIN/EWOULDBLOCK or EINPROGRESS. 它将因EAGAIN / EWOULDBLOCK或EINPROGRESS而失败。 select()
with your desired timeout, with the socket set into the writefds
, ie select for writeability. 在套接字设置为writefds
,以所需的超时时间调用select()
,即选择可写性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.