Skip to content

Commit 19dfcb6

Browse files
committed
LINUX: LOF returns available bytes for serial connection
1 parent 7d314d8 commit 19dfcb6

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/common/fs_serial.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <unistd.h>
2020
#include <sys/select.h>
2121
#include <errno.h>
22+
#include <sys/ioctl.h>
2223

2324
/**
2425
* terminal speed
@@ -129,20 +130,9 @@ int serial_read(dev_file_t *f, byte *data, uint32_t size) {
129130

130131
// Returns the number of the available data on serial port
131132
uint32_t serial_length(dev_file_t *f) {
132-
fd_set readfs;
133-
struct timeval tv;
134-
135-
FD_ZERO(&readfs);
136-
FD_SET(f->handle, &readfs);
137-
138-
tv.tv_usec = 250; // milliseconds
139-
tv.tv_sec = 0; // seconds
140-
141-
select(f->handle + 1, &readfs, NULL, NULL, &tv);
142-
if (FD_ISSET(f->handle, &readfs)) {
143-
return 1;
144-
}
145-
return 0;
133+
uint32_t bytes;
134+
ioctl(f->handle, FIONREAD, &bytes);
135+
return bytes;
146136
}
147137

148138
#elif defined(_Win32)

0 commit comments

Comments
 (0)