aboutsummaryrefslogtreecommitdiff
path: root/jim-aio.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2016-09-02 17:05:51 +1000
committerSteve Bennett <steveb@workware.net.au>2016-09-09 17:38:37 +1000
commit685edd21efef7311ad8ef7dcb4023db30201b99f (patch)
tree9e587fa0a7fbcf21ae4d780b8c1e9c41548ef0b2 /jim-aio.c
parent4baa884e739b59dfd50cbf606786c41de1d289a8 (diff)
downloadjimtcl-685edd21efef7311ad8ef7dcb4023db30201b99f.zip
jimtcl-685edd21efef7311ad8ef7dcb4023db30201b99f.tar.gz
jimtcl-685edd21efef7311ad8ef7dcb4023db30201b99f.tar.bz2
aio: add tty settings support (via termios)
Enough to make serial ports work and support raw and cooked input/output Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-aio.c')
-rw-r--r--jim-aio.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/jim-aio.c b/jim-aio.c
index f36acdd..e8af2f3 100644
--- a/jim-aio.c
+++ b/jim-aio.c
@@ -68,6 +68,10 @@
#include <openssl/err.h>
#endif
+#ifdef HAVE_TERMIOS_H
+#include <jim-tty.h>
+#endif
+
#include "jim-eventloop.h"
#include "jim-subcmd.h"
@@ -490,7 +494,6 @@ static void JimAioDelProc(Jim_Interp *interp, void *privData)
SSL_free(af->ssl);
}
#endif
-
if (!(af->openFlags & AIO_KEEPOPEN)) {
fclose(af->fp);
}
@@ -1207,6 +1210,51 @@ static int aio_cmd_unlock(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
}
#endif /* JIM_BOOTSTRAP */
+#if defined(HAVE_TERMIOS_H) && !defined(JIM_BOOTSTRAP)
+static int aio_cmd_tty(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+{
+ AioFile *af = Jim_CmdPrivData(interp);
+ Jim_Obj *dictObjPtr;
+ int ret;
+
+ if (argc == 0) {
+ /* get the current settings as a dictionary */
+ dictObjPtr = Jim_GetTtySettings(interp, af->fd);
+ if (dictObjPtr == NULL) {
+ JimAioSetError(interp, NULL);
+ return JIM_ERR;
+ }
+ Jim_SetResult(interp, dictObjPtr);
+ return JIM_OK;
+ }
+
+ if (argc > 1) {
+ /* Convert name value arguments to a dictionary */
+ dictObjPtr = Jim_NewListObj(interp, argv, argc);
+ }
+ else {
+ /* The settings are already given as a list */
+ dictObjPtr = argv[0];
+ }
+ Jim_IncrRefCount(dictObjPtr);
+
+ if (Jim_ListLength(interp, dictObjPtr) % 2) {
+ /* Must be a valid dictionary */
+ Jim_DecrRefCount(interp, dictObjPtr);
+ return -1;
+ }
+
+ ret = Jim_SetTtySettings(interp, af->fd, dictObjPtr);
+ if (ret < 0) {
+ JimAioSetError(interp, NULL);
+ ret = JIM_ERR;
+ }
+ Jim_DecrRefCount(interp, dictObjPtr);
+
+ return ret;
+}
+#endif /* JIM_BOOTSTRAP */
+
static const jim_subcmd_type aio_command_table[] = {
{ "read",
"?-nonewline? ?len?",
@@ -1397,6 +1445,15 @@ static const jim_subcmd_type aio_command_table[] = {
/* Description: Relase a lock. */
},
#endif /* JIM_BOOTSTRAP */
+#if defined(HAVE_TERMIOS_H) && !defined(JIM_BOOTSTRAP)
+ { "tty",
+ "?baud rate? ?data bits? ?stop bits? ?parity even|odd|none? ?handshake xonxoff|rtscts|none? ?input raw|cooked? ?output raw|cooked? ?vmin n? ?vtime n?",
+ aio_cmd_tty,
+ 0,
+ -1,
+ /* Description: Get or set tty settings - valid only on a tty */
+ },
+#endif /* JIM_BOOTSTRAP */
{ NULL }
};