diff options
author | Jakob Odersky <jodersky@gmail.com> | 2013-07-11 11:40:38 +0200 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2013-07-11 11:40:38 +0200 |
commit | dd264239a59290b37e947afd437dd1bf654c9196 (patch) | |
tree | 7cff173fd7497dafcd675ebff2e6bc438d69920c | |
parent | 13c82b7c449a0af549741d46f5c2586477368b9b (diff) | |
download | akka-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)
-rw-r--r-- | flow-binaries/linux/amd64/libflow.so.1.0 | bin | 13676 -> 13683 bytes | |||
-rw-r--r-- | flow-binaries/linux/amd64/libflow.so.1.1 | bin | 0 -> 13734 bytes | |||
-rw-r--r-- | flow-native/unix/src/flow.c | 26 | ||||
-rw-r--r-- | project/Build.scala | 2 |
4 files changed, 15 insertions, 13 deletions
diff --git a/flow-binaries/linux/amd64/libflow.so.1.0 b/flow-binaries/linux/amd64/libflow.so.1.0 Binary files differindex 9d0c6ed..8a02fed 100644 --- a/flow-binaries/linux/amd64/libflow.so.1.0 +++ b/flow-binaries/linux/amd64/libflow.so.1.0 diff --git a/flow-binaries/linux/amd64/libflow.so.1.1 b/flow-binaries/linux/amd64/libflow.so.1.1 Binary files differnew file mode 100644 index 0000000..ed82d57 --- /dev/null +++ b/flow-binaries/linux/amd64/libflow.so.1.1 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; } } diff --git a/project/Build.scala b/project/Build.scala index 8b84c5b..7bd5196 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -106,7 +106,7 @@ val binaries: Seq[(File, File)] = getLatestBinaries(binDir, BinaryMajorVersion) //--- native unix-like settings ---------------------------------------- - val UnixBinaryMinorVersion = 0 + val UnixBinaryMinorVersion = 1 lazy val unixNativeSettings: Seq[Setting[_]] = commonNativeSettings ++ Seq( flags in Native := Seq("-fPIC", "-O2") |