Merge pull request #174 from Arth-ur/check-tiocgserial-retval
Check return value of ioctl `TIOCGSERIAL` on Linux
This commit is contained in:
commit
c5741a23e4
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue