-
Notifications
You must be signed in to change notification settings - Fork 56
Description
jssc/src/cpp/_nix_based/jssc.cpp
Line 716 in 0d0e6f7
| * Collecting data for EventListener class (Linux have no implementation of "WaitCommEvent" function from Windows) |
So, this line mentions that there's no analogue for WaitCommEvent from WinApi. However, isn't that what poll/epoll/select functions are for? My concern is that for me using this library on Linux causes a memory leak and garbage collection around every 30 seconds (with default flags) when the app is just idle, and I don't think there's a good reason for that.
On Windows this behaviour is not present, of course. Now, I have zero experience with C++ code, so I probably shouldn't try to make a PR with critical code, but could someone take a look at it? Here's the example on SO of using poll on serial port and it's very close to what jSerialComm does:
JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNIEnv *env, jobject obj, jlong serialPortFD)
{
// Initialize the waiting set
if (serialPortFD <= 0)
return 0;
struct pollfd waitingSet = { serialPortFD, POLLIN, 0 };
// Wait for a serial port event
if (poll(&waitingSet, 1, 1000) <= 0)
return 0;
return (waitingSet.revents & POLLIN) ? com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_AVAILABLE : 0;
}
Then there's this blogpost with three different implementations. I just don't know how to connect all that to JNI and what to do with all the lines statuses.
