Hi
I am creating a socket first and then trying to read SO_SNDTIMEO using getsockopt function. But it always returns -1. After that i want to change the SO_SNDTIMEO to 1 seconds. I have updated the structure timeval and put the corresponding numbers in the structure and then calling setsockopt with SO_SNDTIMEO. setsockopt returns 0 which is successfull.Then i am calling connect to connect to a server and the server is off. Since connect is a blocking call, it is coming out of connect around 70 to 80 seconds.
My code:
stcp = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if( stcp == INVALID_SOCKET )
{
printf("failed TCP socket create (%d)\n",fdError());
printf("TCP server Fatal Error\n");
if( stcp != INVALID_SOCKET )
fdClose( stcp );
return(-1);
}
bzero( &sin1, sizeof(struct sockaddr_in) );
sin1.sin_family = AF_INET;
sin1.sin_len = sizeof( sin1 )
sin1.sin_addr.s_addr = htonl(ipAddress);
sin1.sin_port = htons(portNum);
size = sizeof(size);
error = getsockopt(stcp, SOL_SOCKET, SO_SNDTIMEO, &status, &size);
timeout.tv_sec = 0;
timeout.tv_usec = 1000;
sucess = setsockopt( stcp, SOL_SOCKET, SO_SNDTIMEO, (void *)&timeout, sizeof( timeout ) );
result = connect( stcp, &sin1, sizeof(sin1) );
How do we set the number of retries? What i want to do is when the server is off, i want to come out of connect with in 2 or 3 seconds. What are the parameters to be changed in the stack?
Regards
Raju