Login Register






VC++, About "accept" function timeout of question! filter_list
Author
Message
VC++, About "accept" function timeout of question! #1
I want to achieve "accept" function can be timeout. However, after the success of the new connection will be received within the specified timeout off, and I would like to receive new connections can continue to connect.

next is my code:
PHP Code:
...... //Set nonblocking mode connection unsigned long ul=1; int ret=ioctlsocket(destsock,FIONBIO,(unsigned long*)&ul); if(ret==SOCKET_ERROR) { closesocket(destsock); return ; } //Set accept timeout fd_set aptset; struct timeval timeout; FD_ZERO(&aptset); FD_SET(destsock,&aptset); timeout.tv_sec=30; //after 30 second timeout timeout.tv_usec=0; int i=0; while(1) { int ret=select(destsock+1,&aptset,NULL,NULL,&timeout); if(ret==0) //has timeout { i++; continue; } else if(FD_ISSET(destsock,&aptset)) { if((newsock=accept(destsock,(struct sockaddr *)&client2,&size2))<0) { closesocket(destsock); i=0; break; } i++; break; } else { i=0; closesocket(destsock); break; } } ul=0; ret=ioctlsocket(destsock,FIONBIO,(unsigned long*)&ul); if(i<=0) return ; while(1) { ...... result=select(newsock+1,&readfd,&writefd,NULL,&timeset); //timeset is 60 seconds timeout if(result<0 && errno!=EINTR) { [color=#FF0000]//My problems right here,at 30 seconds then abnormal,why?[/color] break; } else if(...) {...} else {...} if(FD_ISSET(newsock,&readfd)) {...} } ......

sorry, my english very poor Sad[/code]

Reply

VC++, About "accept" function timeout of question! #2
I want to achieve "accept" function can be timeout. However, after the success of the new connection will be received within the specified timeout off, and I would like to receive new connections can continue to connect.

next is my code:
PHP Code:
...... //Set nonblocking mode connection unsigned long ul=1; int ret=ioctlsocket(destsock,FIONBIO,(unsigned long*)&ul); if(ret==SOCKET_ERROR) { closesocket(destsock); return ; } //Set accept timeout fd_set aptset; struct timeval timeout; FD_ZERO(&aptset); FD_SET(destsock,&aptset); timeout.tv_sec=30; //after 30 second timeout timeout.tv_usec=0; int i=0; while(1) { int ret=select(destsock+1,&aptset,NULL,NULL,&timeout); if(ret==0) //has timeout { i++; continue; } else if(FD_ISSET(destsock,&aptset)) { if((newsock=accept(destsock,(struct sockaddr *)&client2,&size2))<0) { closesocket(destsock); i=0; break; } i++; break; } else { i=0; closesocket(destsock); break; } } ul=0; ret=ioctlsocket(destsock,FIONBIO,(unsigned long*)&ul); if(i<=0) return ; while(1) { ...... result=select(newsock+1,&readfd,&writefd,NULL,&timeset); //timeset is 60 seconds timeout if(result<0 && errno!=EINTR) { [color=#FF0000]//My problems right here,at 30 seconds then abnormal,why?[/color] break; } else if(...) {...} else {...} if(FD_ISSET(newsock,&readfd)) {...} } ......

sorry, my english very poor Sad[/code]

Reply

RE: VC++, About "accept" function timeout of question! #3
If am not mistaken the value is in microseconds.
Code:
u_long on = 1; timeval tv = {0, 900000}; //timeout value in microseconds fd_set fds; FD_ZERO(&fds);

Reply

RE: VC++, About "accept" function timeout of question! #4
I don't think this is reason, because my others timeout coding is no abnormal.

Reply

RE: VC++, About "accept" function timeout of question! #5
I don't think this is reason, because my others timeout coding is no abnormal.

Reply