aboutsummaryrefslogtreecommitdiff
path: root/flow-native
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2013-07-11 11:40:38 +0200
committerJakob Odersky <jodersky@gmail.com>2013-07-11 11:40:38 +0200
commitdd264239a59290b37e947afd437dd1bf654c9196 (patch)
tree7cff173fd7497dafcd675ebff2e6bc438d69920c /flow-native
parent13c82b7c449a0af549741d46f5c2586477368b9b (diff)
downloadakka-serial-dd264239a59290b37e947afd437dd1bf654c9196.tar.gz
akka-serial-dd264239a59290b37e947afd437dd1bf654c9196.tar.bz2
akka-serial-dd264239a59290b37e947afd437dd1bf654c9196.zip
use select system call instead of poll (because mac doesn't support poll on devices)
Diffstat (limited to 'flow-native')
-rw-r--r--flow-native/unix/src/flow.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/flow-native/unix/src/flow.c b/flow-native/unix/src/flow.c
index 97e8e23..29769d3 100644
--- a/flow-native/unix/src/flow.c
+++ b/flow-native/unix/src/flow.c
@@ -35,7 +35,6 @@
#include <errno.h>
#include <termios.h>
#include <fcntl.h>
-#include <poll.h>
#include "com_github_jodersky_flow_internal_NativeSerial.h"
#include "flow.h"
@@ -187,22 +186,25 @@ int serial_close(struct serial_config* serial) {
}
int serial_read(struct serial_config* serial, unsigned char* buffer, size_t size) {
+ int port = serial->port_fd;
+ int pipe = serial->pipe_read_fd;
- struct pollfd polls[2];
- polls[0].fd = serial->port_fd; // serial poll
- polls[0].events = POLLIN;
+ fd_set rfds;
+ FD_ZERO(&rfds);
+ FD_SET(port, &rfds);
+ FD_SET(pipe, &rfds);
- polls[1].fd = serial->pipe_read_fd; // pipe poll
- polls[1].events = POLLIN;
+ int nfds = pipe + 1;
+ if (pipe < port) nfds = port + 1;
- int n = poll(polls,2,-1);
+ int n = select(nfds, &rfds, NULL, NULL, NULL);
if (n < 0) {
- DEBUG(perror("poll"););
+ DEBUG(perror("select"););
return E_IO;
}
- if ((polls[0].revents & POLLIN) != 0) {
- int r = read(polls[0].fd, buffer, size);
+ if (FD_ISSET(port, &rfds)) {
+ int r = read(port, buffer, size);
//treat 0 bytes read as an error to avoid problems on disconnect
//anyway, after a poll there should be more than 0 bytes available to read
@@ -211,10 +213,10 @@ int serial_read(struct serial_config* serial, unsigned char* buffer, size_t size
return E_IO;
}
return r;
- } else if ((polls[1].revents & POLLIN) != 0) {
+ } else if (FD_ISSET(pipe, &rfds)) {
return E_INTERRUPT;
} else {
- fprintf(stderr, "poll revents: unknown revents\nserial: %d\npipe: %d", polls[0].revents, polls[1].revents);
+ fputs("select: unknown read sets", stderr);
return E_IO;
}
}