]> rtime.felk.cvut.cz Git - sojka/sterm.git/blobdiff - sterm.c
Fix disabling of flow control
[sojka/sterm.git] / sterm.c
diff --git a/sterm.c b/sterm.c
index e9d914abbb4fc4ae71ff56cce1cc2c432d8412fa..127dcea895deb8629b63265f915a640e6777f3c8 100644 (file)
--- a/sterm.c
+++ b/sterm.c
@@ -1,7 +1,7 @@
 /*
  * Simple serial terminal
  *
- * Copyright 2014 Michal Sojka <sojkam1@fel.cvut.cz>
+ * Copyright 2014, 2015 Michal Sojka <sojkam1@fel.cvut.cz>
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -209,10 +209,14 @@ int main(int argc, char *argv[])
        }
        atexit(unlock);
 
-       if ((fd = open(dev, O_RDWR)) < 0) {
+       /* O_NONBLOCK is needed to not wait for the CDC signal. See tty_ioctl(4). */
+       if ((fd = open(dev, O_RDWR|O_NOCTTY|O_NONBLOCK)) < 0) {
                perror(dev);
                exit(1);
        }
+        /* Cancel the efect of O_NONBLOCK flag. */
+       int n = fcntl(fd, F_GETFL, 0);
+        fcntl(fd, F_SETFL, n & ~O_NDELAY);
 
        if (isatty(fd)) {
                CHECK(ioctl(fd, TIOCEXCL, NULL));
@@ -238,6 +242,10 @@ int main(int argc, char *argv[])
                        CHECK(ioctl(fd, TIOCMSET, &status));
                }
 
+                /* Disable flow control */
+               tio.c_cflag &= ~(CRTSCTS);
+               tio.c_iflag &= ~(IXON|IXOFF);
+
                CHECK(tcsetattr(fd, TCSANOW, &tio));
        } else if (speed || dtr || rts) {
                fprintf(stderr, "Cannot set speed, DTR or RTS on non-terminal %s\n", dev);