I am trying to set up timeout for receiving data via socket.
struct timeval
{
time_t tv_sec;
long int tv_usec;
};
struct timeval tv;
tv.tv_sec = 5;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
{
sprintf(RESULTS, "%s","ERROR");
return 0;
}
else
{
/*Connecting to server socket*/
if (connect(sockfd, (SA*)&servaddr, sizeof(servaddr)) != 0)
{
/*Writing results back to COBOL variable*/
sprintf(RESULTS, "%s","!SENT");
return 0;
}
else
{
if(setsockopt(sockfd,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof(tv)) < 0)
{
if(send(sockfd, buff, sizeof(buff), 0)<0)
{
/*Writing results back to COBOL variable*/
sprintf(RESULTS, "%s","ERROR");
/*Closing the socket*/
FILE_CLOSE_((short)sockfd);
return 0;
}
else
{
/* Receiving data from server*/
bzero(buff, sizeof(buff));
recv(sockfd, buff, sizeof(buff),0);
/*Writing results back to COBOL variable*/
sprintf(RESULTS, "%s","SUCCESS");
/*Closing the socket*/
FILE_CLOSE_((short)sockfd);
return 0;
}
}
}
}
Expected output: Program should wait for 5 secs and if it doesn't get reply from the server then it should close the socket and get out of it.
Actual Output: Warning:argument 4 conflicts with formal definition
Implemented based on this example, I found an example in C
But this is not working on Tandem-C
I have referred to the C/C++ programming manual for Tandem but didn't found with timeout. Tandem-Manual-Page 185
Thanks in advance.