winpr-comm: CommWriteFile, completed support of WriteTotalTimeout

This commit is contained in:
Emmanuel Ledoux
2014-05-28 17:18:33 +02:00
committed by Emmanuel Ledoux
parent 4715009965
commit cdbba47eee
2 changed files with 22 additions and 3 deletions

View File

@@ -265,7 +265,11 @@ static void serial_process_irp_read(SERIAL_DEVICE* serial, IRP* irp)
case ERROR_BAD_DEVICE:
irp->IoStatus = STATUS_INVALID_DEVICE_REQUEST;
break;
case ERROR_CANCELLED:
irp->IoStatus = STATUS_CANCELLED;
break;
default:
DEBUG_SVC("unexpected last-error: 0x%x", GetLastError());
irp->IoStatus = STATUS_UNSUCCESSFUL;
@@ -342,6 +346,10 @@ static void serial_process_irp_write(SERIAL_DEVICE* serial, IRP* irp)
irp->IoStatus = STATUS_INVALID_DEVICE_REQUEST;
break;
case ERROR_CANCELLED:
irp->IoStatus = STATUS_CANCELLED;
break;
default:
DEBUG_SVC("unexpected last-error: 0x%x", GetLastError());
irp->IoStatus = STATUS_UNSUCCESSFUL;

View File

@@ -318,6 +318,7 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
{
int biggestFd = -1;
fd_set event_set, write_set;
int nbFds;
biggestFd = pComm->fd_write;
if (pComm->fd_write_event > biggestFd)
@@ -332,13 +333,22 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
FD_SET(pComm->fd_write_event, &event_set);
FD_SET(pComm->fd_write, &write_set);
if (select(biggestFd+1, &event_set, &write_set, NULL, pTimeout) < 0)
nbFds = select(biggestFd+1, &event_set, &write_set, NULL, pTimeout);
if (nbFds < 0)
{
DEBUG_WARN("select() failure, errno=[%d] %s\n", errno, strerror(errno));
SetLastError(ERROR_IO_DEVICE);
return FALSE;
}
if (nbFds == 0)
{
/* timeout */
SetLastError(ERROR_TIMEOUT);
return FALSE;
}
/* event_set */
@@ -391,7 +401,8 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
if (errno == EAGAIN)
{
/* keep on */
continue;
}
else if (errno == EBADF)
{