title: Nonblocking read function
body: <p>I wrote an update function that is called from the main loop. Since the implementation is subjected to certain timing constraints it is programmed in such way that each update function is aloud to take 50 ms max. In the case a function does not return a value within 50 ms the main loop aborts with an error message stating that a certain function took to long. </p>
  
  <p>The issue is that I am trying to read from a earlier setup (opened) socket. Sometimes reading from this socket takes 10 ms, but in other cases it takes 100 ms allowing the main loop to abort. Therefore, it seems to be the case that I wrote this function using blocking methods. I have no idea how I can solve this or even implement a solution to this. Someone gave me the hint to work with a timer. The function is:</p>
  
  <pre><code>int socket_update(void) {
      n = read(sockfd, recvBuff, sizeof(recvBuff)-1);
      if (n &gt; 0) {
         //Run some code    
      } else if (n &lt; 0) {
         printf("\n Read error \n");
         return 0;
     }
     return 1;
  }
  </code></pre>
  
  <p>Therefore, I am under the impression that the read function is blocking the main loop.</p>
  
  <p>How can I solve this?</p>