Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit b3ce3bf

Browse files
committed
posix: Fix timeouts functions for values > 1 second
All the *timeout() functions incorrectly assumed, that that timeout is less than a second. Reporter of this bug would like to remain anonymous, but thanks anyway! Fixes #10. Signed-off-by: Petr Štetiar <[email protected]>
1 parent d32669a commit b3ce3bf

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/rs232_posix.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ rs232_read_timeout_forced(struct rs232_port_t *p, unsigned char *buf,
228228

229229
FD_ZERO(&set);
230230
FD_SET(ux->fd, &set);
231-
tv.tv_sec = 0;
232-
tv.tv_usec = timeout * 1000;
231+
tv.tv_sec = (timeout * 1000) / 1000000;
232+
tv.tv_usec = (timeout * 1000) % 1000000;
233233

234234
*read_len = 0;
235235
gettimeofday(&t1, NULL);
@@ -310,8 +310,8 @@ rs232_read_timeout(struct rs232_port_t *p, unsigned char *buf,
310310

311311
FD_ZERO(&set);
312312
FD_SET(ux->fd, &set);
313-
tv.tv_sec = 0;
314-
tv.tv_usec = timeout * 1000;
313+
tv.tv_sec = (timeout * 1000) / 1000000;
314+
tv.tv_usec = (timeout * 1000) % 1000000;
315315
*read_len = 0;
316316

317317
ret = select(ux->fd+1, &set, NULL, NULL, &tv);
@@ -388,8 +388,8 @@ rs232_write_timeout(struct rs232_port_t *p, const unsigned char *buf,
388388

389389
FD_ZERO(&set);
390390
FD_SET(ux->fd, &set);
391-
tv.tv_sec = 0;
392-
tv.tv_usec = timeout * 1000;
391+
tv.tv_sec = (timeout * 1000) / 1000000;
392+
tv.tv_usec = (timeout * 1000) % 1000000;
393393
*write_len = 0;
394394

395395
ret = select(ux->fd+1, NULL, &set, NULL, &tv);

0 commit comments

Comments
 (0)