ntdll: Implemented IOCTL purge for serial objects.

This commit is contained in:
Eric Pouech 2006-02-06 11:36:19 +01:00 committed by Alexandre Julliard
parent bd8db45e44
commit b83c5ead16
2 changed files with 28 additions and 26 deletions

View File

@ -848,37 +848,19 @@ BOOL WINAPI EscapeCommFunction(
* Terminates pending operations and/or discards buffers on a * Terminates pending operations and/or discards buffers on a
* communication resource. * communication resource.
* *
* PARAMS
*
* handle [in] The communication resource to be purged
* flags [in] Flags for clear pending/buffer on input/output
*
* RETURNS * RETURNS
* *
* True on success and false if the communications handle is bad. * True on success and false if the communications handle is bad.
*/ */
BOOL WINAPI PurgeComm( BOOL WINAPI PurgeComm(HANDLE handle, DWORD flags)
HANDLE handle, /* [in] The communication resource to be purged. */
DWORD flags) /* [in] Flags for clear pending/buffer on input/output. */
{ {
int fd; return DeviceIoControl(handle, IOCTL_SERIAL_PURGE, &flags, sizeof(flags),
NULL, 0, NULL, NULL);
TRACE("handle %p, flags %lx\n", handle, flags);
fd = get_comm_fd( handle, FILE_READ_DATA );
if(fd<0) return FALSE;
/*
** not exactly sure how these are different
** Perhaps if we had our own internal queues, one flushes them
** and the other flushes the kernel's buffers.
*/
if(flags&PURGE_TXABORT)
tcflush(fd,TCOFLUSH);
if(flags&PURGE_RXABORT)
tcflush(fd,TCIFLUSH);
if(flags&PURGE_TXCLEAR)
tcflush(fd,TCOFLUSH);
if(flags&PURGE_RXCLEAR)
tcflush(fd,TCIFLUSH);
release_comm_fd( handle, fd );
return 1;
} }
/***************************************************************************** /*****************************************************************************

View File

@ -129,6 +129,20 @@ static const char* iocode2str(DWORD ioc)
} }
} }
static NTSTATUS purge(int fd, DWORD flags)
{
/*
** not exactly sure how these are different
** Perhaps if we had our own internal queues, one flushes them
** and the other flushes the kernel's buffers.
*/
if (flags & PURGE_TXABORT) tcflush(fd, TCOFLUSH);
if (flags & PURGE_RXABORT) tcflush(fd, TCIFLUSH);
if (flags & PURGE_TXCLEAR) tcflush(fd, TCOFLUSH);
if (flags & PURGE_RXCLEAR) tcflush(fd, TCIFLUSH);
return STATUS_SUCCESS;
}
/****************************************************************** /******************************************************************
* COMM_DeviceIoControl * COMM_DeviceIoControl
* *
@ -156,6 +170,12 @@ NTSTATUS COMM_DeviceIoControl(HANDLE hDevice,
switch (dwIoControlCode) switch (dwIoControlCode)
{ {
case IOCTL_SERIAL_PURGE:
if (lpInBuffer && nInBufferSize == sizeof(DWORD))
status = purge(fd, *(DWORD*)lpInBuffer);
else
status = STATUS_INVALID_PARAMETER;
break;
case IOCTL_SERIAL_SET_BREAK_OFF: case IOCTL_SERIAL_SET_BREAK_OFF:
#if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */ #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
if (ioctl(fd, TIOCCBRK, 0) == -1) if (ioctl(fd, TIOCCBRK, 0) == -1)