TCP connect in Non Blocking Mode
- From: Prabhu <yesprabhu@xxxxxxxxx>
- Date: Tue, 22 Apr 2008 07:33:39 -0700 (PDT)
Hi,
My client application tries to connect to the server in the following
manner:
...../
err = connect(sd, (struct sockaddr*) &sa, sizeof(sa));
if(err == -1)
{
if(errno == EINPROGRESS)
{
struct timeval l_connect_timeout;
int l_fds;
l_connect_timeout.tv_usec=0;
l_connect_timeout.tv_sec=30; //30 seconds.
while(1)
{
l_fds=select(sd+1, NULL,&filedes_set,NULL,
&l_connect_timeout);
if(l_fds == 0) //timed out
return 0;
else if(l_fds < 0) //select failed
return 0;
else
{
int l_sock_optval=-1;
int
l_sock_optval_len=sizeof(l_sock_optval);
if(getsockopt(sd,
SOL_SOCKET, SO_ERROR, (int*)&l_sock_optval,
(socklen_t*)&l_sock_optval_len) !=0)
{
return 0;
}
if(l_sock_optval == 0)
{
//connected to
server
break;
}
}
}
}
This works fine. The issue that I face is when the server refuses
connection by sending RST for the SYN from client. The select waits
for 30 seconds and later returns timing out. RST though is sent
immediately by the server. The client application need to capture the
RST as soon as it arrives. How do we achieve that. Why does not the
select return immediately when the RST arrives at client?
Thanks,
Prabhu. S
.
- Follow-Ups:
- Re: TCP connect in Non Blocking Mode
- From: Rainer Temme
- Re: TCP connect in Non Blocking Mode
- Prev by Date: Re: stack, pop, push and min in o(1)
- Next by Date: Bit bucket directory
- Previous by thread: Longines Ladies Watches DolceVita L5.155.4.84.6 - AA - Replica Watch Fake
- Next by thread: Re: TCP connect in Non Blocking Mode
- Index(es):
Relevant Pages
|