title: What are reasons that read() on a POSIX serial port might be slow?
body: <p>I'm writing a console application under Ubuntu that uses the serial port. It needs to read and write from the serial port at 60 Hz.</p>
  
  <p>I find that the call to read() is often, but not always, slow. I have set O_NDELAY, so often it returns immediately (great). Sometimes it takes up to 50 ms to finish, and that is too slow for my application. Before calling read(), I check the number of chars available, so it should not be waiting for data.</p>
  
  <p>What is read() doing that takes so long? How can I speed it up?</p>
  
  <p>Options on the port are:</p>
  
  <pre><code>options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &amp;= ~PARENB;
  options.c_cflag &amp;= ~CSTOPB;
  options.c_cflag &amp;= ~CSIZE;
  options.c_cflag |= CS8;
  
  options.c_lflag &amp;= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_iflag &amp;= ~IXON;
  
  options.c_oflag = 0;
  </code></pre>
  
  <p>edit: I'd been using select() earlier but it turned out to be orthogonal to the question. Updated with my latest information.</p>