diff options
author | Steve Bennett <steveb@workware.net.au> | 2020-04-20 20:59:04 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2020-05-06 11:23:14 +1000 |
commit | 46bbf5470e373d3b2a8282fe7b90d30c8da598fa (patch) | |
tree | 6190bde00c8a446fcab7c977b40500c2e17fd1c3 | |
parent | 3c99fff83e7224ebe348c4840e13444e74f185a3 (diff) | |
download | jimtcl-46bbf5470e373d3b2a8282fe7b90d30c8da598fa.zip jimtcl-46bbf5470e373d3b2a8282fe7b90d30c8da598fa.tar.gz jimtcl-46bbf5470e373d3b2a8282fe7b90d30c8da598fa.tar.bz2 |
aio: Add socket pty
Allows a psuedo-tty pair to be created.
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | auto.def | 5 | ||||
-rw-r--r-- | jim-aio.c | 37 | ||||
-rw-r--r-- | jim_tcl.txt | 5 |
3 files changed, 45 insertions, 2 deletions
@@ -122,7 +122,7 @@ if {[opt-bool coverage]} { } cc-check-includes time.h sys/time.h sys/socket.h netinet/in.h arpa/inet.h netdb.h -cc-check-includes sys/un.h dlfcn.h unistd.h dirent.h crt_externs.h +cc-check-includes util.h pty.h sys/un.h dlfcn.h unistd.h dirent.h crt_externs.h # Check sizeof time_t so we can warn on non-Y2038 compliance cc-with {-includes time.h} { @@ -152,6 +152,9 @@ cc-check-functions localtime gmtime strptime clock_gettime if {[cc-check-function-in-lib backtrace execinfo]} { define-append LDLIBS [get-define lib_backtrace] } +if {[cc-check-function-in-lib openpty util]} { + define-append LDLIBS [get-define lib_openpty] +} if {[cc-check-functions sysinfo]} { cc-with {-includes sys/sysinfo.h} { @@ -51,6 +51,12 @@ #include <unistd.h> #include <sys/stat.h> #endif +#ifdef HAVE_UTIL_H +#include <util.h> +#endif +#ifdef HAVE_PTY_H +#include <pty.h> +#endif #include "jim.h" #include "jimiocompat.h" @@ -2001,7 +2007,7 @@ static AioFile *JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *fi return af; } -#if defined(HAVE_PIPE) || (defined(HAVE_SOCKETPAIR) && UNIX_SOCKETS) +#if defined(HAVE_PIPE) || (defined(HAVE_SOCKETPAIR) && UNIX_SOCKETS) || defined(HAVE_OPENPTY) /** * Create a pair of channels. e.g. from pipe() or socketpair() */ @@ -2046,6 +2052,26 @@ static int JimAioPipeCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) } #endif +#ifdef HAVE_OPENPTY +static int JimAioOpenPtyCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + int p[2]; + static const char * const mode[2] = { "r+", "w+" }; + + if (argc != 1) { + Jim_WrongNumArgs(interp, 1, argv, ""); + return JIM_ERR; + } + + if (openpty(&p[0], &p[1], NULL, NULL, NULL) != 0) { + JimAioSetError(interp, NULL); + return JIM_ERR; + } + + return JimMakeChannelPair(interp, p, argv[0], "aio.pty%ld", 0, mode); +} +#endif + #if defined(HAVE_SOCKETS) && !defined(JIM_BOOTSTRAP) static int JimAioSockCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) @@ -2061,6 +2087,7 @@ static int JimAioSockCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) "stream.server", "pipe", "pair", + "pty", NULL }; enum @@ -2075,6 +2102,7 @@ static int JimAioSockCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) SOCK_STREAM_SERVER, SOCK_STREAM_PIPE, SOCK_STREAM_SOCKETPAIR, + SOCK_STREAM_PTY, }; int socktype; int sock; @@ -2221,6 +2249,13 @@ static int JimAioSockCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) family = PF_UNIX; break; #endif +#ifdef HAVE_OPENPTY + case SOCK_STREAM_PTY: + if (addr || ipv6) { + goto wrongargs; + } + return JimAioOpenPtyCommand(interp, 1, &argv[1]); +#endif default: Jim_SetResultString(interp, "Unsupported socket type", -1); diff --git a/jim_tcl.txt b/jim_tcl.txt index 73c0593..24c380b 100644 --- a/jim_tcl.txt +++ b/jim_tcl.txt @@ -62,6 +62,7 @@ Changes between 0.78 and 0.79 6. Add support for `json::encode` and `json::decode` 7. `aio tty` now allows setting +echo+ without full +raw+ mode 8. `regsub` now fully supports +{backslash}A+ +9. Add `socket pty` to create a pseudo-tty pair Changes between 0.77 and 0.78 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -4981,6 +4982,10 @@ Various socket types may be created. A socketpair (see socketpair(2)). Like `pipe`, this command returns a list of two channels: {s1 s2}. These channels are both readable and writable. ++*socket pty*+:: + A pseudo-tty pair (see openpty(3)). Like `pipe`, this command returns + a list of two channels: {master slave}. These channels are both readable and writable. + This command creates a socket connected (client) or bound (server) to the given address. |