Reinitialize timeout struct on each use

This commit is contained in:
hedgecrw85 2018-08-01 09:42:25 -05:00
parent 8e0afa07af
commit d03189929b
21 changed files with 18 additions and 9 deletions

View File

@ -377,15 +377,18 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNI
if (serialPortFD <= 0)
return 0;
// Initialize the waiting set and the timeouts
struct timeval timeout = { 1, 0 };
// Initialize the waiting set
fd_set waitingSet;
FD_ZERO(&waitingSet);
FD_SET(serialPortFD, &waitingSet);
// Wait for a serial port event
int retVal;
do { retVal = select(serialPortFD + 1, &waitingSet, NULL, NULL, &timeout); } while ((retVal < 0) && (errno == EINTR));
do
{
struct timeval timeout = { 1, 0 };
retVal = select(serialPortFD + 1, &waitingSet, NULL, NULL, &timeout);
} while ((retVal < 0) && ((errno == EINTR) || (errno == EAGAIN)));
if (retVal <= 0)
return 0;
return (FD_ISSET(serialPortFD, &waitingSet)) ? com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_AVAILABLE : 0;

View File

@ -306,15 +306,18 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNI
if (serialPortFD <= 0)
return 0;
// Initialize the waiting set and the timeouts
struct timeval timeout = { 1, 0 };
// Initialize the waiting set
fd_set waitingSet;
FD_ZERO(&waitingSet);
FD_SET(serialPortFD, &waitingSet);
// Wait for a serial port event
int retVal;
do { retVal = select(serialPortFD + 1, &waitingSet, NULL, NULL, &timeout); } while ((retVal < 0) && (errno == EINTR));
do
{
struct timeval timeout = { 1, 0 };
retVal = select(serialPortFD + 1, &waitingSet, NULL, NULL, &timeout);
} while ((retVal < 0) && ((errno == EINTR) || (errno == EAGAIN)));
if (retVal <= 0)
return 0;
return (FD_ISSET(serialPortFD, &waitingSet)) ? com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_AVAILABLE : 0;

View File

@ -342,15 +342,18 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNI
if (serialPortFD <= 0)
return 0;
// Initialize the waiting set and the timeouts
struct timeval timeout = { 1, 0 };
// Initialize the waiting set
fd_set waitingSet;
FD_ZERO(&waitingSet);
FD_SET(serialPortFD, &waitingSet);
// Wait for a serial port event
int retVal;
do { retVal = select(serialPortFD + 1, &waitingSet, NULL, NULL, &timeout); } while ((retVal < 0) && (errno == EINTR));
do
{
struct timeval timeout = { 1, 0 };
retVal = select(serialPortFD + 1, &waitingSet, NULL, NULL, &timeout);
} while ((retVal < 0) && ((errno == EINTR) || (errno == EAGAIN)));
if (retVal <= 0)
return 0;
return (FD_ISSET(serialPortFD, &waitingSet)) ? com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_AVAILABLE : 0;