2022-02-14 15:08:28 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must repipeduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PIPEVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
2022-06-11 05:32:01 +00:00
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
2022-02-14 15:08:28 +00:00
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PIPECUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PIPEFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _HIO_PTY_H_
|
|
|
|
#define _HIO_PTY_H_
|
|
|
|
|
|
|
|
#include <hio.h>
|
|
|
|
|
|
|
|
typedef struct hio_dev_pty_t hio_dev_pty_t;
|
|
|
|
|
|
|
|
typedef int (*hio_dev_pty_on_read_t) (
|
|
|
|
hio_dev_pty_t* dev,
|
|
|
|
const void* data,
|
|
|
|
hio_iolen_t len
|
|
|
|
);
|
|
|
|
|
|
|
|
typedef int (*hio_dev_pty_on_write_t) (
|
|
|
|
hio_dev_pty_t* dev,
|
|
|
|
hio_iolen_t wrlen,
|
|
|
|
void* wrctx
|
|
|
|
);
|
|
|
|
|
|
|
|
typedef void (*hio_dev_pty_on_close_t) (
|
|
|
|
hio_dev_pty_t* dev
|
|
|
|
);
|
|
|
|
|
2022-02-14 16:57:17 +00:00
|
|
|
typedef int (*hio_dev_pty_on_fork_t) (
|
|
|
|
hio_dev_pty_t* dev,
|
|
|
|
void* fork_ctx
|
|
|
|
);
|
|
|
|
|
2022-02-14 15:08:28 +00:00
|
|
|
struct hio_dev_pty_t
|
|
|
|
{
|
|
|
|
HIO_DEV_HEADER;
|
|
|
|
|
2022-02-15 11:14:10 +00:00
|
|
|
hio_syshnd_t hnd;
|
2022-02-14 16:57:17 +00:00
|
|
|
hio_intptr_t child_pid;
|
|
|
|
int flags;
|
2022-02-14 15:08:28 +00:00
|
|
|
|
|
|
|
hio_dev_pty_on_read_t on_read;
|
|
|
|
hio_dev_pty_on_write_t on_write;
|
|
|
|
hio_dev_pty_on_close_t on_close;
|
|
|
|
};
|
|
|
|
|
2022-02-14 16:57:17 +00:00
|
|
|
enum hio_dev_pty_make_flag_t
|
|
|
|
{
|
2022-02-15 11:14:10 +00:00
|
|
|
HIO_DEV_PTY_UCMD = (1 << 12), /* cmd is hio_uch_t* */
|
2022-02-14 16:57:17 +00:00
|
|
|
HIO_DEV_PTY_SHELL = (1 << 13),
|
|
|
|
/* perform no waitpid() on a child process upon device destruction.
|
2023-01-11 14:59:41 +00:00
|
|
|
* you should set this flag if your application has automatic child
|
2022-02-14 16:57:17 +00:00
|
|
|
* process reaping enabled. for instance, SIGCHLD is set to SIG_IGN
|
|
|
|
* on POSIX.1-2001 compliant systems */
|
|
|
|
HIO_DEV_PTY_FORGET_CHILD = (1 << 14),
|
|
|
|
HIO_DEV_PTY_FORGET_DIEHARD_CHILD = (1 << 15)
|
|
|
|
};
|
|
|
|
typedef enum hio_dev_pty_make_flag_t hio_dev_pty_make_flag_t;
|
|
|
|
|
2022-02-14 15:08:28 +00:00
|
|
|
typedef struct hio_dev_pty_make_t hio_dev_pty_make_t;
|
|
|
|
struct hio_dev_pty_make_t
|
|
|
|
{
|
2022-02-14 16:57:17 +00:00
|
|
|
int flags; /**< bitwise-ORed of hio_dev_pty_make_flag_t enumerators */
|
2022-02-15 11:14:10 +00:00
|
|
|
const void* cmd; /* the actual type is determined by HIO_DEV_PTY_UCMD */
|
2022-02-14 16:57:17 +00:00
|
|
|
|
2022-02-14 15:08:28 +00:00
|
|
|
hio_dev_pty_on_write_t on_write; /* mandatory */
|
|
|
|
hio_dev_pty_on_read_t on_read; /* mandatory */
|
|
|
|
hio_dev_pty_on_close_t on_close; /* optional */
|
2022-02-14 16:57:17 +00:00
|
|
|
hio_dev_pty_on_fork_t on_fork; /* optional */
|
|
|
|
void* fork_ctx;
|
2022-02-14 15:08:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum hio_dev_pty_ioctl_cmd_t
|
|
|
|
{
|
2022-02-14 16:57:17 +00:00
|
|
|
HIO_DEV_PTY_CLOSE,
|
|
|
|
HIO_DEV_PTY_KILL_CHILD
|
2022-02-14 15:08:28 +00:00
|
|
|
};
|
|
|
|
typedef enum hio_dev_pty_ioctl_cmd_t hio_dev_pty_ioctl_cmd_t;
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
HIO_EXPORT hio_dev_pty_t* hio_dev_pty_make (
|
|
|
|
hio_t* hio,
|
|
|
|
hio_oow_t xtnsize,
|
|
|
|
const hio_dev_pty_make_t* data
|
|
|
|
);
|
|
|
|
|
|
|
|
#if defined(HIO_HAVE_INLINE)
|
|
|
|
static HIO_INLINE hio_t* hio_dev_pty_gethio (hio_dev_pty_t* pty) { return hio_dev_gethio((hio_dev_t*)pty); }
|
2022-02-15 11:14:10 +00:00
|
|
|
static HIO_INLINE void* hio_dev_pty_getxtn (hio_dev_pty_t* pty) { return (void*)(pty + 1); }
|
|
|
|
static HIO_INLINE hio_syshnd_t hio_dev_pty_getsyshnd (hio_dev_pty_t* pty) { return pty->hnd; }
|
2022-02-14 15:08:28 +00:00
|
|
|
#else
|
|
|
|
# define hio_dev_pty_gethio(pty) hio_dev_gethio(pty)
|
2022-02-15 11:14:10 +00:00
|
|
|
# define hio_dev_pty_getxtn(pty) ((void*)(((hio_dev_pty_t*)pty) + 1))
|
|
|
|
# define hio_dev_pty_getsyshnd(pty) (((hio_dev_pty_t*)pty)->hnd)
|
2022-02-14 15:08:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HIO_HAVE_INLINE)
|
|
|
|
#else
|
|
|
|
#endif
|
|
|
|
|
|
|
|
HIO_EXPORT void hio_dev_pty_kill (
|
|
|
|
hio_dev_pty_t* pty
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT void hio_dev_pty_halt (
|
|
|
|
hio_dev_pty_t* pty
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_dev_pty_read (
|
|
|
|
hio_dev_pty_t* pty,
|
|
|
|
int enabled
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_dev_pty_timedread (
|
|
|
|
hio_dev_pty_t* pty,
|
|
|
|
int enabled,
|
|
|
|
const hio_ntime_t* tmout
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_dev_pty_write (
|
|
|
|
hio_dev_pty_t* pty,
|
|
|
|
const void* data,
|
|
|
|
hio_iolen_t len,
|
|
|
|
void* wrctx
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_dev_pty_timedwrite (
|
|
|
|
hio_dev_pty_t* pty,
|
|
|
|
const void* data,
|
|
|
|
hio_iolen_t len,
|
|
|
|
const hio_ntime_t* tmout,
|
|
|
|
void* wrctx
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_dev_pty_close (
|
|
|
|
hio_dev_pty_t* pty
|
|
|
|
);
|
|
|
|
|
2022-02-14 16:57:17 +00:00
|
|
|
HIO_EXPORT int hio_dev_pty_killchild (
|
|
|
|
hio_dev_pty_t* pro
|
|
|
|
);
|
|
|
|
|
2022-02-14 15:08:28 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|