Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

call to Connect

Status
Not open for further replies.

logic4fun

Programmer
Apr 24, 2003
85
US
Hi all,
I am trying to call Connect system function in my client application and when the box is offnet or powered down it is taking awful lot of time to return from that call. I want to wrap around this function a timer so that..it waits for that time and returns out of that. but as i am a newbie to the socket program..cant really figure out how to accomplish this. following is a simple call i am using

while(connect(sock,(struct sockaddr *)&portaddr,sizeof(portaddr))<0) {
if(NETtimedout) {
close(sock);
return(-4);
}

I want to just wait for 5 secs and close Socket. any ideas how to write a wrapper around this.

Thanks in advance
prasad
 
I also tried using an alarm signal call but it never comes out of the connect. I tried using

signal(SIGALRM,catchSig);
alarm(5);

before the call to connect. it catches the signal but it never comes out of connect. Any Suggestions ????
 
The same code works fine on AIX. but not LINUX redhat 8.1. Means it catches signals..and exits out on our AIX box but not on LINUX box
 
Here is what exactly i need to implement

int timeOut;
void catchSig(int sig) {
timeOut = 1;
}

then i call the system function connect as follows by giving a prior call to sigAlrm

signal(SIGALRM,catchSig);
alarm(5);
while(connect(sock,(struct sockaddr *)&portaddr,sizeof(portaddr))<0) {
if(NETtimedout) {
close(sock);
return(-4);
}

When i try to connect a box which is offnet After 5 secs of timeout value the alarm is getting fired but the connect call is not returning it goes to a mode where it sets to ERESTARTSYS. and hangs on there itself until it gets ETIMEDOUT. ANY help ??
thanks in advance
logic4fun
 
Hello logic4fun,

Have a look to sigaction(2) manual page of your system.
The SA_RESTART flag is maybe by default on ... in this case,
the system calls are re-started after an interrupt.

Hope this help!
By,
FlorianB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top