From 46bbf5470e373d3b2a8282fe7b90d30c8da598fa Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Mon, 20 Apr 2020 20:59:04 +1000 Subject: aio: Add socket pty Allows a psuedo-tty pair to be created. Signed-off-by: Steve Bennett --- jim-aio.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'jim-aio.c') diff --git a/jim-aio.c b/jim-aio.c index 56c8adf..1efa58e 100644 --- a/jim-aio.c +++ b/jim-aio.c @@ -51,6 +51,12 @@ #include #include #endif +#ifdef HAVE_UTIL_H +#include +#endif +#ifdef HAVE_PTY_H +#include +#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); -- cgit v1.1