* fhandler_serial.cc (fhandler_serial::tcflush): Simplify. Remove

read polling loop to avoid a hang with streaming devices.
This commit is contained in:
Corinna Vinschen 2003-12-11 18:07:42 +00:00
parent 992406a5ea
commit 97cb9b9de4
2 changed files with 28 additions and 14 deletions

View File

@ -1,3 +1,8 @@
2003-12-11 Brian Ford <ford@vss.fsi.com>
* fhandler_serial.cc (fhandler_serial::tcflush): Simplify. Remove
read polling loop to avoid a hang with streaming devices.
2003-12-11 Christopher Faylor <cgf@redhat.com> 2003-12-11 Christopher Faylor <cgf@redhat.com>
* pinfo.cc (_pinfo::set_ctty): Correct stupid typo. * pinfo.cc (_pinfo::set_ctty): Correct stupid typo.

View File

@ -497,21 +497,30 @@ fhandler_serial::ioctl (unsigned int cmd, void *buffer)
int int
fhandler_serial::tcflush (int queue) fhandler_serial::tcflush (int queue)
{ {
if (queue == TCOFLUSH || queue == TCIOFLUSH) DWORD flags;
PurgeComm (get_handle (), PURGE_TXABORT | PURGE_TXCLEAR);
if (queue == TCIFLUSH || queue == TCIOFLUSH) switch (queue)
/* Input flushing by polling until nothing turns up {
(we stop after 1000 chars anyway) */ case TCOFLUSH:
for (int max = 1000; max > 0; max--) flags = PURGE_TXABORT | PURGE_TXCLEAR;
{ break;
COMSTAT st; case TCIFLUSH:
if (!PurgeComm (get_handle (), PURGE_RXABORT | PURGE_RXCLEAR)) flags = PURGE_RXABORT | PURGE_RXCLEAR;
break; break;
low_priority_sleep (100); case TCIOFLUSH:
if (!ClearCommError (get_handle (), &ev, &st) || !st.cbInQue) flags = PURGE_TXABORT | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_RXCLEAR;
break; break;
} default:
termios_printf ("Invalid tcflush queue %d", queue);
set_errno (EINVAL);
return -1;
}
if (!PurgeComm (get_handle (), flags))
{
__seterrno ();
return -1;
}
return 0; return 0;
} }