From aa9f121a125e359951f9e92d08ba5a865b8231c0 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Tue, 6 Apr 2021 15:50:59 -0700 Subject: [PATCH] add support for high bps on OS X --- configure.ac | 3 +++ src/Makefile.am | 4 ++++ src/iossiospeed.c | 28 ++++++++++++++++++++++++++++ src/tty.c | 23 +++++++++++++++++++++-- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/iossiospeed.c diff --git a/configure.ac b/configure.ac index 55da367..125c22e 100644 --- a/configure.ac +++ b/configure.ac @@ -88,6 +88,9 @@ AC_DEFINE_UNQUOTED([AUTOCONF_BAUDRATE_CASES],[$BAUDRATE_CASES],[Switch cases for AC_CHECK_DECL([TCGETS2], [AC_DEFINE([HAVE_TERMIOS2],[1],[Define if termios2 exists.]) have_termios2=yes], , [[#include ]]) AM_CONDITIONAL([ADD_SETSPEED2],[test "x$have_termios2" = "xyes"]) +AC_CHECK_DECL([IOSSIOSPEED], [AC_DEFINE([HAVE_IOSSIOSPEED],[1],[Define if IOKit exists.]) have_iossiospeed=yes], , [[#include ]]) +AM_CONDITIONAL([ADD_IOSSIOSPEED],[test "x$have_iossiospeed" = "xyes"]) + AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([src/Makefile]) AC_CONFIG_FILES([src/bash-completion/tio]) diff --git a/src/Makefile.am b/src/Makefile.am index 046c599..0925fd2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,10 @@ if ADD_SETSPEED2 tio_SOURCES += setspeed2.c endif +if ADD_IOSSIOSPEED +tio_SOURCES += iossiospeed.c +endif + if ENABLE_BASH_COMPLETION bashcompletiondir=@BASH_COMPLETION_DIR@ bashcompletion_DATA=bash-completion/tio diff --git a/src/iossiospeed.c b/src/iossiospeed.c new file mode 100644 index 0000000..e2ffe2e --- /dev/null +++ b/src/iossiospeed.c @@ -0,0 +1,28 @@ +/* + * tio - a simple TTY terminal I/O application + * + * Copyright (c) 2017 Martin Lund + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include +#include + +int iossiospeed(int fd, int baudrate) +{ + return ioctl(fd, IOSSIOSPEED, (char *)&baudrate); +} diff --git a/src/tty.c b/src/tty.c index 067179a..6500f61 100644 --- a/src/tty.c +++ b/src/tty.c @@ -48,6 +48,10 @@ extern int setspeed2(int fd, int baudrate); #endif +#ifdef HAVE_IOSSIOSPEED +extern int iossiospeed(int fd, int baudrate); +#endif + static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old; static unsigned long rx_total = 0, tx_total = 0; static bool connected = false; @@ -366,7 +370,7 @@ void tty_configure(void) AUTOCONF_BAUDRATE_CASES default: -#ifdef HAVE_TERMIOS2 +#if defined(HAVE_TERMIOS2) || defined(HAVE_IOSSIOSPEED) standard_baudrate = false; break; #else @@ -663,6 +667,11 @@ int tty_connect(void) /* Save current port settings */ if (tcgetattr(fd, &tio_old) < 0) goto error_tcgetattr; +#ifdef HAVE_IOSSIOSPEED + /* OS X wants these fields left alone. We'll set baudrate with iossiospeed below. */ + tio.c_ispeed = tio_old.c_ispeed; + tio.c_ospeed = tio_old.c_ospeed; +#endif /* Make sure we restore tty settings on exit */ if (first) @@ -689,6 +698,16 @@ int tty_connect(void) } } #endif +#ifdef HAVE_IOSSIOSPEED + if (!standard_baudrate) + { + if (iossiospeed(fd, option.baudrate) != 0) + { + error_printf_silent("Could not set baudrate speed (%s)", strerror(errno)); + goto error_setspeed2; + } + } +#endif maxfd = MAX(fd, STDIN_FILENO) + 1; /* Maximum bit entry (fd) to test */ @@ -827,7 +846,7 @@ int tty_connect(void) return TIO_SUCCESS; -#ifdef HAVE_TERMIOS2 +#if defined(HAVE_TERMIOS2) || defined(HAVE_IOSSIOSPEED) error_setspeed2: #endif error_tcsetattr: