Is there is a timeout crossplatform soulution to accept client using accept
function without setting socket to non-blocking?
I know that i should use select
function to it, but what i'm doing wrong?
SOCKET NativesAcceptClient(SOCKET s, int timeout)
{
int iResult;
struct timeval tv;
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(s, &rfds);
tv.tv_sec = (long)timeout;
tv.tv_usec = 0;
iResult = select(s, &rfds, (fd_set *) 0, (fd_set *) 0, &tv);
if(iResult > 0)
{
return accept(s, NULL, NULL);
}
else
{
//always here, even if i connect from another application
}
return 0;
}
How to fix that?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…