I'm hoping some Unix GURU can give me a quick one-liner to help me fix this problem...
I have serial input and output working fine through the IOKit (yes, the termios stuff). I have it configured not to block on reads, but I do want it to block on writes.
The problem I'm having is that in one situation, the port gets closed shortly after it's written to, and the last several bytes get chopped off. I've tried using O_FSYNC, and tcdrain, but it still gets chopped off. If I block the thread for about 200ms, none of the data is lost, but I'm running in a time-critical environment, so losing 200ms is a big deal. BTW, I do have the thread running in real-time priority, so if I don't block, external threads don't run ( it's really funny to hear iTunes just stop and see the mouse freeze when the thread starts doing heavy computation w/o blocking ).
Anyway, I'm basically looking for a way to ensure that all data has been written from the serial output buffer before the function moves on. All the documentation I've found on the internet says tcdrain is what I need, but Apple's website says that tcdrain only passes the command on to the serial driver. BTW, the issue occurs with both a Keyspan and an FTDI adapter, so it's not likely to be a driver issue.
Thanks for any input you can offer.