title: how to detect a buffer over run on serial port in linux using c++
body: <p>I have a big problem. At present I am accessing a serial port via the following hooks:</p>
  
  <pre><code>fd = open( "/dev/ttyS1", O_RDWR | O_NOCTTY )
  </code></pre>
  
  <p>then I read from it using the following chunk of code</p>
  
  <pre><code>i = select( fd + 1, &amp;rfds, NULL, NULL, &amp;tv )
  ...
  iLen = read( fd, buf, MAX_PACKET_LEN )
  </code></pre>
  
  <p>the problem is that before I read, I need to detect if there were any buffer overruns. Both at the serial port level and the internal tty flip buffers.</p>
  
  <p>We tried <code>cat /proc/tty/driver/serial</code> but it doesn't seem to list the overruns (see output below)</p>
  
  <pre><code>1: uart:16550A port:000002F8 irq:3 tx:70774 rx:862484 fe:44443 pe:270023 brk:30301 RTS|CTS|DTR
  </code></pre>