winpr-comm: need to purge _purge()'s events before read and write operations
This commit is contained in:
parent
f26c7ee498
commit
16b6c44ef7
@ -92,7 +92,6 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
int biggestFd = -1;
|
||||
fd_set read_set;
|
||||
int nbFds;
|
||||
ssize_t nbRead = 0;
|
||||
COMMTIMEOUTS *pTimeouts;
|
||||
UCHAR vmin = 0;
|
||||
UCHAR vtime = 0;
|
||||
@ -211,7 +210,7 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
currentTermios.c_cc[VTIME] = vtime;
|
||||
|
||||
// TMP:
|
||||
fprintf(stderr, "Applying timeout VMIN=%u, VTIME=%u", vmin, vtime);
|
||||
fprintf(stderr, "MANU: Applying timeout VMIN=%u, VTIME=%u\n", vmin, vtime);
|
||||
|
||||
if (tcsetattr(pComm->fd, TCSANOW, ¤tTermios) < 0)
|
||||
{
|
||||
@ -221,9 +220,10 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* FIXME: had expected eventfd_write() to return EAGAIN when
|
||||
* there is no eventfd_read() but this not the case. */
|
||||
/* discard a possible and no more relevant event */
|
||||
eventfd_read(pComm->fd_read_event, NULL);
|
||||
|
||||
biggestFd = pComm->fd_read;
|
||||
if (pComm->fd_read_event > biggestFd)
|
||||
@ -269,7 +269,7 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_WARN("unexpected error on reading fd_write_event, errno=[%d] %s\n", errno, strerror(errno));
|
||||
DEBUG_WARN("unexpected error on reading fd_read_event, errno=[%d] %s\n", errno, strerror(errno));
|
||||
/* FIXME: return FALSE ? */
|
||||
}
|
||||
|
||||
@ -287,6 +287,8 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
|
||||
if (FD_ISSET(pComm->fd_read, &read_set))
|
||||
{
|
||||
ssize_t nbRead = 0;
|
||||
|
||||
nbRead = read(pComm->fd_read, lpBuffer, nNumberOfBytesToRead);
|
||||
if (nbRead < 0)
|
||||
{
|
||||
@ -374,6 +376,12 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
|
||||
return TRUE; /* FIXME: or FALSE? */
|
||||
}
|
||||
|
||||
/* FIXME: had expected eventfd_write() to return EAGAIN when
|
||||
* there is no eventfd_read() but this not the case. */
|
||||
/* discard a possible and no more relevant event */
|
||||
eventfd_read(pComm->fd_write_event, NULL);
|
||||
|
||||
|
||||
/* ms */
|
||||
ULONGLONG Tmax = nNumberOfBytesToWrite * pComm->timeouts.WriteTotalTimeoutMultiplier + pComm->timeouts.WriteTotalTimeoutConstant;
|
||||
|
||||
|
@ -1095,10 +1095,10 @@ static BOOL _set_queue_size(WINPR_COMM *pComm, const SERIAL_QUEUE_SIZE *pQueueSi
|
||||
/* FIXME: could be implemented on top of N_TTY */
|
||||
|
||||
if (pQueueSize->InSize > N_TTY_BUF_SIZE)
|
||||
DEBUG_WARN("Requested an incompatible input buffer size: %lu", pQueueSize->InSize);
|
||||
DEBUG_WARN("Requested an incompatible input buffer size: %lu, keeping on with a %lu bytes buffer.", pQueueSize->InSize, N_TTY_BUF_SIZE);
|
||||
|
||||
if (pQueueSize->OutSize > N_TTY_BUF_SIZE)
|
||||
DEBUG_WARN("Requested an incompatible output buffer size: %lu", pQueueSize->OutSize);
|
||||
DEBUG_WARN("Requested an incompatible output buffer size: %lu, keeping on with a %lu bytes buffer.", pQueueSize->OutSize, N_TTY_BUF_SIZE);
|
||||
|
||||
SetLastError(ERROR_CANCELLED);
|
||||
return FALSE;
|
||||
@ -1144,7 +1144,7 @@ static BOOL _purge(WINPR_COMM *pComm, const ULONG *pPurgeMask)
|
||||
{
|
||||
DEBUG_WARN("eventfd_write failed, errno=[%d] %s", errno, strerror(errno));
|
||||
}
|
||||
|
||||
|
||||
assert(errno == EAGAIN); /* no reader <=> no pending IRP_MJ_READ */
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user