title: 'close' function on serial port descriptor blocks in linux
body: <p>Recently I've found a problem which is quite new for me and I'd appreciate advice. I'm doing serial communication on Linux using termios functions. I actually don't use real serial port, but virtual gadget serial driver <code>/dev/ttyGS0</code>. File descriptor is opened as non-blocking.</p>
  
  <p>My program periodically generates data and sends it to /dev/ttyGS0. There is no information if the other end reads it or not. If it does not, some internal fifo fills up and write returns "would block" error. So far so good, I have no problems with that.</p>
  
  <p>Problem is, when I want to close such file descriptor with filled fifo, close functions blocks! Not indefinitely, but for about 10 seconds. </p>
  
  <p>I tried to do <code>tcflush(uart-&gt;fd, TCOFLUSH)</code> before closing without any effect.</p>
  
  <p>This is so strange behavior to me and I found no description, that close could block. Is there any way how to avoid this? Or at least decrease this timeout? Where should I look for this timeout? VTIME attribute has also no effect to this.</p>