Merge pull request #174 from Arth-ur/check-tiocgserial-retval

Check return value of ioctl `TIOCGSERIAL` on Linux
This commit is contained in:
Will Hedgecock 2018-12-07 09:30:14 -06:00 committed by GitHub
commit c5741a23e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View File

@ -510,13 +510,15 @@ int setBaudRateCustom(int portFD, baud_rate baudRate)
int retVal = ioctl(portFD, TCSETS2, &options);
#else
struct serial_struct serInfo;
ioctl(portFD, TIOCGSERIAL, &serInfo);
serInfo.flags &= ~ASYNC_SPD_MASK;
serInfo.flags |= ASYNC_SPD_CUST | ASYNC_LOW_LATENCY;
serInfo.custom_divisor = serInfo.baud_base / baudRate;
if (sersInfo.custom_divisor == 0)
serInfo.custom_divisor = 1;
int retVal = ioctl(portFD, TIOCSSERIAL, &serInfo);
int retVal = ioctl(portFD, TIOCGSERIAL, &serInfo);
if (retVal == 0) {
serInfo.flags &= ~ASYNC_SPD_MASK;
serInfo.flags |= ASYNC_SPD_CUST | ASYNC_LOW_LATENCY;
serInfo.custom_divisor = serInfo.baud_base / baudRate;
if (sersInfo.custom_divisor == 0)
serInfo.custom_divisor = 1;
retVal = ioctl(portFD, TIOCSSERIAL, &serInfo);
}
#endif
return (retVal == 0);
}

View File

@ -336,9 +336,11 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
// Attempt to set the transmit buffer size and any necessary custom baud rates
#if defined(__linux__)
struct serial_struct serInfo;
ioctl(serialPortFD, TIOCGSERIAL, &serInfo);
serInfo.xmit_fifo_size = sendDeviceQueueSize;
ioctl(serialPortFD, TIOCSSERIAL, &serInfo);
int tiocgserialRetVal = ioctl(serialPortFD, TIOCGSERIAL, &serInfo);
if (tiocgserialRetVal == 0) {
serInfo.xmit_fifo_size = sendDeviceQueueSize;
ioctl(serialPortFD, TIOCSSERIAL, &serInfo);
}
#endif
if (nonStandardBaudRate)
setBaudRateCustom(serialPortFD, baudRate);