aboutsummaryrefslogtreecommitdiff
path: root/toys/net
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-08-17 23:02:00 -0500
committerRob Landley <rob@landley.net>2018-08-17 23:02:00 -0500
commit17a2d5783ac38d1b79f37e2524d390ac7386dbf4 (patch)
tree1595c2a1c488c44241174fadd9ab55a756dc4053 /toys/net
parent151e3f782333acbe349fdaac3ec843e42e95be3f (diff)
downloadtoybox-17a2d5783ac38d1b79f37e2524d390ac7386dbf4.tar.gz
Make microcom use set_terminal() and move speed setting into set_terminal().
Diffstat (limited to 'toys/net')
-rw-r--r--toys/net/microcom.c30
1 files changed, 3 insertions, 27 deletions
diff --git a/toys/net/microcom.c b/toys/net/microcom.c
index d34e1fee..62fe85e6 100644
--- a/toys/net/microcom.c
+++ b/toys/net/microcom.c
@@ -26,22 +26,7 @@ GLOBALS(
struct termios original_stdin_state, original_fd_state;
)
-// Puts `fd` into raw mode, setting the baud rate if `speed` != 0,
-// and saving the original terminal state.
-static void xraw(int fd, const char *name, speed_t speed,
- struct termios *original)
-{
- struct termios t;
-
- if (tcgetattr(fd, &t)) perror_exit("tcgetattr %s", name);
- *original = t;
-
- cfmakeraw(&t);
- if (speed) cfsetspeed(&t, speed);
-
- if (tcsetattr(fd, TCSAFLUSH, &t)) perror_exit("tcsetattr %s", name);
-}
-
+// TODO: tty_sigreset outputs ansi escape sequences, how to disable?
static void restore_states(int i)
{
tcsetattr(0, TCSAFLUSH, &TT.original_stdin_state);
@@ -50,29 +35,20 @@ static void restore_states(int i)
void microcom_main(void)
{
- int speeds[] = {50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
- 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800,
- 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000,
- 2500000, 3000000, 3500000, 4000000};
struct pollfd fds[2];
int i, speed;
if (!TT.s) speed = 115200;
else speed = atoi(TT.s);
- // Find speed in table, adjust to constant
- for (i = 0; i < ARRAY_LEN(speeds); i++) if (speeds[i] == speed) break;
- if (i == ARRAY_LEN(speeds)) error_exit("unknown speed: %s", TT.s);
- speed = i+1+4081*(i>15);
-
// Open with O_NDELAY, but switch back to blocking for reads.
TT.fd = xopen(*toys.optargs, O_RDWR | O_NOCTTY | O_NDELAY);
if (-1==(i = fcntl(TT.fd, F_GETFL, 0)) || fcntl(TT.fd, F_SETFL, i&~O_NDELAY))
perror_exit_raw(*toys.optargs);
// Set both input and output to raw mode.
- xraw(TT.fd, "fd", speed, &TT.original_fd_state);
- xraw(0, "stdin", 0, &TT.original_stdin_state);
+ xset_terminal(TT.fd, 1, speed, &TT.original_fd_state);
+ set_terminal(0, 1, 0, &TT.original_stdin_state);
// ...and arrange to restore things, however we may exit.
sigatexit(restore_states);