Skip to content

Commit

Permalink
Log-and-retry if waitEvents fails in place of giving up.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenalpha committed Nov 27, 2024
1 parent 4a3e150 commit 9548f42
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main/java/jssc/SerialPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;

import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

/**
*
* @author scream3r
*/
@SuppressWarnings("unused")
public class SerialPort {

private static final Logger log = getLogger(SerialPort.class);
private final SerialNativeInterface serialInterface;
private SerialPortEventListener eventListener;
private volatile long portHandle;
Expand Down Expand Up @@ -1206,10 +1211,19 @@ private class EventThread extends Thread {
public void run() {
while(!threadTerminated){
int[][] eventArray;
try{
try {
eventArray = waitEvents();
}catch( IOException ex ){
throw new RuntimeException("Failed in waitEvents()", ex);
} catch (IOException ex) {
if (log.isDebugEnabled()) log.warn("waitEvents() failed", ex);
else log.warn("waitEvents() failed: {}", ex.getMessage());
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
log.debug("Got interrupted", ex);
Thread.currentThread().interrup();
threadTerminated = true;
}
continue;
}
for(int[] event : eventArray){
if(event[0] > 0 && !threadTerminated){
Expand Down

0 comments on commit 9548f42

Please sign in to comment.