title: How can I clear socket buffer in linux
body: <p>I have a question about socket programming.  I want to clear the socket buffer.
  I tried the following code:</p>
  
  <pre><code>int ret_read = read(return_events[index].data.fd, recv_buffer, sizeof(recv_buffer));
  if(-1 == ret_read)
  {
      if(EAGAIN != errno)
      {
          printf("read data from %d error occured, errno=%d, %s.\n", return_events[index].data.fd, errno, strerror(errno));
          /**
          Tag-position, I know buffer is not empty. I wonder clear buffer in code position.The buffer is socket recv buffer, is not recv_buffer.
          */
      }
      continue;
  }
  </code></pre>
  
  <p>I don't want to use <code>read()</code> again in Tag-position, becase I want to set the buffer to empty.  Though using <code>read()</code> in Tag-position, I think it may fail.</p>
  
  <p>Is there anyone who can tell me another way except <code>read()</code> in Tag-position?</p>