Merge pull request #2205 from eledoux/ports

winpr-comm: ignore errors on TIOCGICOUNT during the port initialization.
This commit is contained in:
Marc-André Moreau 2014-11-12 14:21:38 -05:00
commit 49e5edebbe
3 changed files with 41 additions and 14 deletions

View File

@ -175,7 +175,7 @@ static void serial_process_irp_create(SERIAL_DEVICE* serial, IRP* irp)
if (!serial->hComm || (serial->hComm == INVALID_HANDLE_VALUE))
{
WLog_Print(serial->log, WLOG_WARN, "CreateFile failure: %s last-error: Ox%lX\n", serial->device.name, GetLastError());
WLog_Print(serial->log, WLOG_WARN, "CreateFile failure: %s last-error: 0x%lX\n", serial->device.name, GetLastError());
irp->IoStatus = STATUS_UNSUCCESSFUL;
goto error_handle;

View File

@ -1373,9 +1373,17 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0)
{
CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s", errno, strerror(errno));
SetLastError(ERROR_IO_DEVICE);
goto error_handle;
CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s.", errno, strerror(errno));
CommLog_Print(WLOG_WARN, "could not read counters.");
/* could not initialize counters but keep on.
*
* Not all drivers, especially for USB to serial
* adapters (e.g. those based on pl2303), does support
* this call.
*/
ZeroMemory(&(pComm->counters), sizeof(struct serial_icounter_struct));
}

View File

@ -1042,11 +1042,19 @@ static BOOL _set_wait_mask(WINPR_COMM *pComm, const ULONG *pWaitMask)
if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0)
{
CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s", errno, strerror(errno));
SetLastError(ERROR_IO_DEVICE);
LeaveCriticalSection(&pComm->EventsLock);
return FALSE;
CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s.", errno, strerror(errno));
if (pComm->permissive)
{
/* counters could not be reset but keep on */
ZeroMemory(&(pComm->counters), sizeof(struct serial_icounter_struct));
}
else
{
SetLastError(ERROR_IO_DEVICE);
LeaveCriticalSection(&pComm->EventsLock);
return FALSE;
}
}
pComm->PendingEvents = 0;
@ -1188,11 +1196,22 @@ static BOOL _get_commstatus(WINPR_COMM *pComm, SERIAL_STATUS *pCommstatus)
ZeroMemory(&currentCounters, sizeof(struct serial_icounter_struct));
if (ioctl(pComm->fd, TIOCGICOUNT, &currentCounters) < 0)
{
CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s", errno, strerror(errno));
SetLastError(ERROR_IO_DEVICE);
LeaveCriticalSection(&pComm->EventsLock);
return FALSE;
CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s.", errno, strerror(errno));
CommLog_Print(WLOG_WARN, " coult not read counters.");
if (pComm->permissive)
{
/* Errors and events based on counters could not be
* detected but keep on.
*/
ZeroMemory(&currentCounters, sizeof(struct serial_icounter_struct));
}
else
{
SetLastError(ERROR_IO_DEVICE);
LeaveCriticalSection(&pComm->EventsLock);
return FALSE;
}
}
/* NB: preferred below (currentCounters.* != pComm->counters.*) over (currentCounters.* > pComm->counters.*) thinking the counters can loop */