title: C/C++ recv() with timeout
body: <p>Hoping someone can help me out. I'm wanting to implement some sort of timeout if my socket is not able to receive data in a certain amount of time... I've looked up ways online but the examples I've looked at doesn't have their recv() in a while loop like mine, they typically just receive the whole buffer that is waiting. Maybe mine just isn't very efficient and someone could point me in a better direction in receiving all the data.</p>
  
  <p>The string that is to be received is not a fixed length which is why I receive 1 at a time because I don't know how big the string might be. As you can see my recv() will receive data until it finds the End of text character ().  The examples with select() I found would use the select before calling receive, but should I be doing that for each go around of my while loop? or maybe call select() before I even enter the while loop?</p>
  
  <p>Anyways, any help is appreciated.</p>
  
  <pre><code>string recv_data(int socket){
  
  bool endfound = false;
  char temp[1];
  string recvstring ;
  while(endfound == false)//receives 1 character at a time until ETX(\x03)character is found
  {
      if(recv(socket,temp,sizeof(temp),0)&lt;0)
      {
          perror("error in recv data");
      }
  
      if(memchr(temp,'\x03',1) != NULL) 
      {
          endfound = true;
      }
  
      recvstring += temp;
      temp[0] = 0;
  }
  
  return formatting(recvstring);
  }
  </code></pre>