win: stream_init() issue with tty on Windows #9884

ref #9825
This commit is contained in:
erw7 2019-04-28 18:46:48 +09:00 committed by Justin M. Keyes
parent cf80fd9e02
commit 8072f085d2
5 changed files with 19 additions and 15 deletions

View File

@ -21,16 +21,14 @@
#endif
void rstream_init_fd(Loop *loop, Stream *stream, int fd, size_t bufsize)
FUNC_ATTR_NONNULL_ARG(1)
FUNC_ATTR_NONNULL_ARG(2)
FUNC_ATTR_NONNULL_ARG(1, 2)
{
stream_init(loop, stream, fd, NULL);
rstream_init(stream, bufsize);
}
void rstream_init_stream(Stream *stream, uv_stream_t *uvstream, size_t bufsize)
FUNC_ATTR_NONNULL_ARG(1)
FUNC_ATTR_NONNULL_ARG(2)
FUNC_ATTR_NONNULL_ARG(1, 2)
{
stream_init(NULL, stream, -1, uvstream);
rstream_init(stream, bufsize);
@ -138,6 +136,10 @@ static void read_cb(uv_stream_t *uvstream, ssize_t cnt, const uv_buf_t *buf)
}
// Called by the by the 'idle' handle to emulate a reading event
//
// Idle callbacks are invoked once per event loop:
// - to perform some very low priority activity.
// - to keep the loop "alive" (so there is always an event to process)
static void fread_idle_cb(uv_idle_t *handle)
{
uv_fs_t req;

View File

@ -53,9 +53,19 @@ void stream_init(Loop *loop, Stream *stream, int fd, uv_stream_t *uvstream)
stream->uv.idle.data = stream;
} else {
assert(type == UV_NAMED_PIPE || type == UV_TTY);
#ifdef WIN32
if (type == UV_TTY) {
uv_tty_init(&loop->uv, &stream->uv.tty, fd, 0);
uv_tty_set_mode(&stream->uv.tty, UV_TTY_MODE_RAW);
stream->uvstream = STRUCT_CAST(uv_stream_t, &stream->uv.tty);
} else {
#endif
uv_pipe_init(&loop->uv, &stream->uv.pipe, 0);
uv_pipe_open(&stream->uv.pipe, fd);
stream->uvstream = STRUCT_CAST(uv_stream_t, &stream->uv.pipe);
#ifdef WIN32
}
#endif
}
}

View File

@ -36,6 +36,9 @@ struct stream {
uv_pipe_t pipe;
uv_tcp_t tcp;
uv_idle_t idle;
#ifdef WIN32
uv_tty_t tty;
#endif
} uv;
uv_stream_t *uvstream;
uv_buf_t uvbuf;

View File

@ -49,15 +49,7 @@ void tinput_init(TermInput *input, Loop *loop)
int curflags = termkey_get_canonflags(input->tk);
termkey_set_canonflags(input->tk, curflags | TERMKEY_CANON_DELBS);
// setup input handle
#ifdef WIN32
uv_tty_init(&loop->uv, &input->tty_in, 0, 1);
uv_tty_set_mode(&input->tty_in, UV_TTY_MODE_RAW);
rstream_init_stream(&input->read_stream,
(uv_stream_t *)&input->tty_in,
0xfff);
#else
rstream_init_fd(loop, &input->read_stream, input->in_fd, 0xfff);
#endif
// initialize a timer handle for handling ESC with libtermkey
time_watcher_init(loop, &input->timer_handle, input);
}

View File

@ -17,9 +17,6 @@ typedef struct term_input {
#endif
TimeWatcher timer_handle;
Loop *loop;
#ifdef WIN32
uv_tty_t tty_in;
#endif
Stream read_stream;
RBuffer *key_buffer;
uv_mutex_t key_buffer_mutex;