Do not block-drain serial port before closing

This commit is contained in:
Will Hedgecock 2022-02-14 12:36:06 -06:00
parent faffe075c8
commit 60ed45bb5d
29 changed files with 7 additions and 4 deletions

View File

@ -2,7 +2,7 @@
* PosixHelperFunctions.h
*
* Created on: Mar 10, 2015
* Last Updated on: Jan 24, 2022
* Last Updated on: Feb 14, 2022
* Author: Will Hedgecock
*
* Copyright (C) 2012-2022 Fazecast, Inc.
@ -98,6 +98,8 @@ void searchForComPorts(serialPortVector* comPorts);
// Apple-specific functionality
#elif defined(__APPLE__)
#define fdatasync fsync
#include <termios.h>
typedef speed_t baud_rate;
void searchForComPorts(serialPortVector* comPorts);

View File

@ -2,7 +2,7 @@
* SerialPort_Posix.c
*
* Created on: Feb 25, 2012
* Last Updated on: Jan 28, 2022
* Last Updated on: Feb 14, 2022
* Author: Will Hedgecock
*
* Copyright (C) 2012-2022 Fazecast, Inc.
@ -803,8 +803,7 @@ JNIEXPORT jlong JNICALL Java_com_fazecast_jSerialComm_SerialPort_closePortNative
tcsetattr(port->handle, TCSANOW, &options);
// Unblock, unlock, and close the port
fsync(port->handle);
tcdrain(port->handle);
fdatasync(port->handle);
tcflush(port->handle, TCIOFLUSH);
flock(port->handle, LOCK_UN | LOCK_NB);
while (close(port->handle) && (errno == EINTR))

View File

@ -1765,6 +1765,8 @@ public final class SerialPort
try
{
// Wait until the event-reading thread returns. This thread MUST return or the serial port will
// be in an unspecified, possibly unrecoverable state
do
{
serialEventThread.join(500);