diff options
author | Jakob Odersky <jodersky@gmail.com> | 2013-06-19 17:07:15 +0200 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2013-06-19 17:07:15 +0200 |
commit | 05ae5ad725d7577b64444eebfe304d0637df216b (patch) | |
tree | 8b7d80f50ff74a746374ad752c476fb858f5ae7c /src/main | |
parent | 9be0db6d86df1a56eca443ababba095d3aea688e (diff) | |
download | akka-serial-05ae5ad725d7577b64444eebfe304d0637df216b.tar.gz akka-serial-05ae5ad725d7577b64444eebfe304d0637df216b.tar.bz2 akka-serial-05ae5ad725d7577b64444eebfe304d0637df216b.zip |
Fix memory issue in native source, pollfd structures are no longer copied.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/native/flow.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/main/native/flow.c b/src/main/native/flow.c index 09ffca6..24e4cb3 100644 --- a/src/main/native/flow.c +++ b/src/main/native/flow.c @@ -178,24 +178,22 @@ int serial_read(struct serial_config* serial, unsigned char * buffer, size_t siz return E_POINTER; } - struct pollfd sp; //serial poll - sp.fd = serial->fd; - sp.events = POLLIN; - struct pollfd pp; //pipe poll - pp.fd = serial->pipe_read; - pp.events = POLLIN; + struct pollfd polls[2]; + polls[0].fd = serial->fd; // serial poll + polls[0].events = POLLIN; - struct pollfd poll_list[] = {sp, pp}; + polls[1].fd = serial->pipe_read; // pipe poll + polls[1].events = POLLIN; - int n = poll(poll_list,(unsigned long)3,-1); + int n = poll(polls,2,-1); if (n < 0) { DEBUG(perror("read")); return E_IO; } - if (sp.revents & POLLIN != 0) { - int r = read(sp.fd, buffer, size); + if ((polls[0].revents & POLLIN) != 0) { + int r = read(polls[0].fd, 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 @@ -291,4 +289,3 @@ JNIEXPORT void JNICALL Java_com_github_jodersky_flow_low_NativeSerial_debug { debug = (bool) value; } - |