-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Result -1 of Select() when reading from disconnected (USB) serial-port causes infinite loop #126
Comments
@factoritbv thanks kindly for this. As a casual JNI user, I wasn't aware how to raise the exception. The "backwards compatibility" is simply a comment from @hiddenalpha's PR here: https://github.com/java-native/jssc/pull/90/files. The project has no issue with raising exceptions. We'd happily accept a PR which patches this behavior. A bit of a disclaimer... this project has been on "life support" here for a while. Although I'm comfortable with the build system, I'm not very comfortable with the C++ portions and for that reason, improvements have been very slow to adopt here. The fork was originally created to keep a dependant project alive and that continues to be my motivating factor. Unfortunately, this dependant project uses jssc sparingly, so focus on bugs usually is a direct result of issues over there. So that's a long-winded way to say that we'd love these improvements incorporated and we're willing to help test them, but we need some help on the C++ side, preferably in the form of a PR. 🍻 |
Alright, we have created a PR. We experienced that with these improvement the library works very stable in a multi-threaded environment, handles serial port disconnects better and is much more user friendly because of the input/output stream add-on. We look forward to your test results. |
Relates to java-native#126 Taken from d4150ed.
Relates to java-native#126 Taken from 11afc8fea9e108ca7baa918a0230fe54c13512b3.
Relates to java-native#126 Taken from d4150ed.
Relates to java-native#126 Taken from 19610bc.
In case of a USB CDC/ACM device, a file descriptor for the emulated serial port /dev/... is provided by an Unix based system.
In such a case, it can happen that the USB device is disconnected. This will cause that the
select()
that is executed with the corresponding file descriptor returns -1.If this is happening, the code below, will end up in an infinite loop. Because the
continue
let the code-flow jump to thewhile(true)
, which then triggers anotherselect()
execution that again will return -1. Which triggers looping again.jssc/src/main/cpp/_nix_based/jssc.cpp
Lines 537 to 559 in 1aff5f9
Better would be if a exception is raised (the java way), however, if this breaks compatibility (like the comments in the code suggest), then at least
awaitReadReady()
should return an error code (in stead of void). The return value should be checked upon in the caller function of course, and should propagate toJava_jssc_SerialNativeInterface_readBytes()
and trigger an immediate return. Again also here, proper handling should be notified towards the calling application. Simply the best way, would by using Java Exceptions.Potential proposal for fixing the READ issue in
Java_jssc_SerialNativeInterface_readBytes
would be:Also important, with high throughput traffic,
select()
also should be used in theJava_jssc_SerialNativeInterface_writeBytes
function. It is possible that the writes are done faster by the caller application, than the (kernel) output buffer and device speed can handle. Also theselect()
return value of -1 can be observed failures in writing to the serial-port.Code proposal to improve the WRITE functionality in the
Java_jssc_SerialNativeInterface_writeBytes
function:The text was updated successfully, but these errors were encountered: