SO_RCVTIMEO is simply not creating a timeout condition in my output functions. I'm designing a file transfer service using a ARQ Sliding Window protocol. To keep things orderly, I'm starting with basic Stop-and-Wait.
This is my initialization of timeval
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 100000;
This is my use of that structure and the socket in preparing a recvfrom timeout
if(setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))<0)
{
fprintf(stderr, "Error in socket option for Timeout mechanism: %s",strerror(errno));
close(sock);
exit(EXIT_FAILURE);
}
if (-1 == bind(sock,(struct sockaddr *)&sa, sizeof(sa)))
{
perror("error bind failed");
close(sock);
exit(EXIT_FAILURE);
}
This is the body of code that is supposed to timeout:
for(;;)
{
...
while((read_bytes=fread((char*)&(packet.body),sizeof(char),CHUNKSIZE,out_file))
{
...
while(1)
{
bytes_sent = sendto(sock, (struct sanpacket*)&packet, sizeof(struct sanpacket), 0,(struct sockaddr*)&sa, sizeof sa);
if (bytes_sent < 0)
{
fprintf(stderr, "%s\n", strerror(errno));
exit(EXIT_FAILURE);
}
printf("Waiting for ACK packet\n");
recsize = recvfrom(sock, (struct sanpacket*)&packet, sizeof(struct sanpacket), 0, (struct sockaddr*)&sa, &fromlen);
if(errno == EAGAIN)
{
printf("Timed out; resending packet with sequence number %d", packet.sequence_num);
continue;
}
if (recsize < 0)
{
fprintf(stderr, "%s\n", strerror(errno));
exit(EXIT_FAILURE);
}
}
The problem: the timeout isn't firing, but setsockopt isn't returning any errors either. I have no way of knowing what I'm doing wrong.
If there's anything else I can do to clarify my question or the environment, please let me know. And I'd appreciate it if you had any suggestions about debugging this.