title: recvfrom function is blocked
body: <p>I have following two files </p>
  
  <p>Client.c</p>
  
  <pre><code>int main(void)
  {
      struct sockaddr_in si_other;
      int s, i, slen=sizeof(si_other);
      char buf[BUFLEN];
  
      if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
          exit(-1);
  
      memset((char *) &amp;si_other, 0, sizeof(si_other));
      si_other.sin_family = AF_INET;
      si_other.sin_port = htons(PORT);
  
      if (inet_aton(SRV_IP, &amp;si_other.sin_addr)==0) 
      {
          fprintf(stderr, "inet_aton() failed\n");
          exit(1);
      }
  
      for (i=0; i&lt;NPACK; i++) 
      {
          printf("Sending packet %d\n", i);
          sprintf(buf, "This is packet %d\n", i);
  
          if (sendto(s, buf, BUFLEN, 0, &amp;si_other, slen)==-1)
          exit(1);
      }
  
      sleep(10);
      close(s);
      return 0;
  }
  </code></pre>
  
  <p>Server.c</p>
  
  <pre><code>int tries=0;   /* Count of times sent - GLOBAL for signal-handler access */
  
  void diep(char *s)
  {
      perror(s);
      exit(1);
  }
  
  
  void CatchAlarm(int ignored)     /* Handler for SIGALRM */
  {
      tries += 1;
  }
  
  void DieWithError(char *errorMessage)
  {}
  
  /* Error handling function */
  void *print_message_function( void *ptr )
  {
      char *message;
  
      usleep(6200*1000);
      message = (char *) ptr;
      printf("%s \n", message);
      sleep(20);
  }
  
  int main(void)
  {
      struct sockaddr_in si_me, si_other;
      int s, i, slen=sizeof(si_other);
      struct sigaction myAction;       /* For setting signal handler */
      const char *message1 = "Thread 1====================================";
      char buf[BUFLEN];
      pthread_t thread1, thread2;
      pthread_create( &amp;thread1, NULL, print_message_function, (void*) message1);
      if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
      diep("socket");
      myAction.sa_handler = CatchAlarm;
      if (sigfillset(&amp;myAction.sa_mask) &lt; 0) /* block everything in handler */
      DieWithError("sigfillset() failed");
      myAction.sa_flags = 0;
  
      if (sigaction(SIGALRM, &amp;myAction, 0) &lt; 0)
      DieWithError("sigaction() failed for SIGALRM");
      memset((char *) &amp;si_me, 0, sizeof(si_me));
      si_me.sin_family = AF_INET;
      si_me.sin_port = htons(PORT);
      si_me.sin_addr.s_addr = htonl(INADDR_ANY);
      if (bind(s, &amp;si_me, sizeof(si_me))==-1)
      diep("bind");
      alarm(TIMEOUT_SECS); 
      for (i=0; i&lt;NPACK; i++) {
      if (recvfrom(s, buf, BUFLEN, 0, &amp;si_other, &amp;slen)==-1)
      {
      printf("Inside eagain %d\n",errno);
      if(errno == EINTR)
        {
            alarm(TIMEOUT_SECS);        /* Set the timeout */
        }
      else
        exit(-1);
      }
      else
      printf("Received packet from %s:%d\nData: %s\n\n", 
      inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port), buf);
  
      }
      alarm(0);
  
      pthread_join( thread1, NULL);
      close(s);
      return 0;
  }
  </code></pre>
  
  <p>I am running Server first then Client. In some occurrences Server is not able to receive the message sent my client. Though client sent it successfully. Even EINTR error also I am getting because of alarm but still recvfrom function is getting blocked in between</p>