X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=dart%2Fttyread.c;h=65f0203ac9d008bf34783d3b6eeb17b60bbe471f;hb=9b57ad36fa772a94f8f38321a88f2b1df1818a51;hp=65a6248ed05e83c87f948d0fc180a887fdbb4f4d;hpb=bd1f47a70c33f1a9861feeb363adb9c65f679dfe;p=svn42.git diff --git a/dart/ttyread.c b/dart/ttyread.c index 65a6248..65f0203 100644 --- a/dart/ttyread.c +++ b/dart/ttyread.c @@ -51,7 +51,6 @@ int setup_tty(int fd) } tmio.c_lflag &= ~ECHO; - tmio.c_lflag &= ~ISIG; tmio.c_lflag |= CLOCAL; tmio.c_iflag &= ~ICRNL; @@ -98,7 +97,7 @@ int main(int argc, char* argv[]) return 1; } - int fd = open(argv[1], O_RDONLY); + int fd = open(argv[1], O_RDONLY | O_NONBLOCK | O_NOCTTY); if(fd < 0) { perror("open()"); return 2; @@ -106,10 +105,24 @@ int main(int argc, char* argv[]) if(setup_tty(fd)) return 3; + fd_set rfds, efds; char buf[100]; for(;;) { + FD_ZERO(&rfds); + FD_SET(fd, &rfds); + FD_ZERO(&efds); + FD_SET(1, &efds); + + int s = select(fd+1, &rfds, NULL, &efds, NULL); + if(s < 0) { + perror("select()"); + return s; + } + if(FD_ISSET(1, &efds)) return 0; + if(!FD_ISSET(fd, &rfds)) continue; + ssize_t r = read(fd, buf, sizeof(buf)); - if(r < 0 ) { + if(r <= 0) { perror("read()"); return r; }