Commit a7ec5da
committed
Make writeBytes() return how many bytes actually got written
The core change is this one:
--- src/main/java/jssc/SerialNativeInterface.java
+++ src/main/java/jssc/SerialNativeInterface.java
@@ -278,5 +278,5 @@ public class SerialNativeInterface {
* @return If the operation is successfully completed, the method returns true, otherwise false
*/
- public native boolean writeBytes(long handle, byte[] buffer) throws IOException;
+ public native int writeBytes(long handle, byte[] buffer) throws IOException;
/**
Essentially changing the return type of `writeBytes()` from `boolean` to
`int`. The reason behind this is that we can return how many bytes
actually got written, in place of just true/false.
Basically, this is a very small change. Nevertheless, there are some
consequences.
This is (kind of) a breaking change for the java API. But still not
really an issue, as it is a very easy migration. About how to migrate,
one can just do the same as done in `SerialPort.writeBytes1()` (notice
the '1' in the name). Just check if returned value matches the length of
the passed-in array. There is also a YAGNI approach (NOT RECOMMENDED!):
One could just use `writeBytes1()` instead. Which provides the old
behavior.
A more severe issue can arise because it potentially also breaks the ABI.
make sure to NOT mix usage of parts of jssc built before or after
this change! in most cases this shouldn't be an issue, as jssc unpacks
the correct version from its JAR anyway. BUT FOR THOSE WHO DID SEPARATE
THE JAVA CODE FROM THE NATIVE CODE AND INSTALL IT SEPARATELY, THEY
POTENTIALLY CAN END UP IN TROUBLE WHEN NOT TAKING CARE HERE.
In addition, this commit also contains some minor cleanups and fixes
some compiler warnings.
Related:
- #129
(wip @ 17cc247)1 parent 4b167f2 commit a7ec5da
File tree
5 files changed
+110
-222
lines changed- src/main
- cpp
- _nix_based
- windows
- java/jssc
5 files changed
+110
-222
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
| |||
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
43 | | - | |
44 | 42 | | |
45 | 43 | | |
46 | 44 | | |
| |||
62 | 60 | | |
63 | 61 | | |
64 | 62 | | |
65 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
66 | 73 | | |
67 | 74 | | |
68 | 75 | | |
| |||
529 | 536 | | |
530 | 537 | | |
531 | 538 | | |
532 | | - | |
| 539 | + | |
533 | 540 | | |
534 | | - | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
535 | 544 | | |
536 | | - | |
537 | | - | |
| 545 | + | |
| 546 | + | |
538 | 547 | | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
545 | 553 | | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
550 | 557 | | |
551 | | - | |
552 | | - | |
| 558 | + | |
553 | 559 | | |
554 | 560 | | |
555 | | - | |
556 | 561 | | |
557 | | - | |
558 | | - | |
| 562 | + | |
| 563 | + | |
559 | 564 | | |
560 | 565 | | |
561 | 566 | | |
| |||
676 | 681 | | |
677 | 682 | | |
678 | 683 | | |
679 | | - | |
| 684 | + | |
680 | 685 | | |
681 | 686 | | |
682 | 687 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
33 | 42 | | |
34 | 43 | | |
35 | 44 | | |
| |||
232 | 241 | | |
233 | 242 | | |
234 | 243 | | |
235 | | - | |
| 244 | + | |
236 | 245 | | |
237 | 246 | | |
238 | 247 | | |
239 | 248 | | |
240 | | - | |
241 | | - | |
| 249 | + | |
| 250 | + | |
242 | 251 | | |
243 | | - | |
| 252 | + | |
244 | 253 | | |
245 | 254 | | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
250 | 259 | | |
251 | 260 | | |
252 | 261 | | |
253 | 262 | | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
262 | 269 | | |
263 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
264 | 290 | | |
265 | 291 | | |
266 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
267 | 299 | | |
268 | 300 | | |
269 | 301 | | |
| |||
298 | 330 | | |
299 | 331 | | |
300 | 332 | | |
301 | | - | |
| 333 | + | |
302 | 334 | | |
303 | 335 | | |
304 | 336 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | | - | |
| 280 | + | |
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| |||
0 commit comments