Prepare for writable TTY to be blocking
This commit is contained in:
parent
41e8574920
commit
5656e3c8bd
@ -99,7 +99,8 @@ typedef int uv_file;
|
|||||||
ngx_queue_t write_completed_queue; \
|
ngx_queue_t write_completed_queue; \
|
||||||
int delayed_error; \
|
int delayed_error; \
|
||||||
uv_connection_cb connection_cb; \
|
uv_connection_cb connection_cb; \
|
||||||
int accepted_fd;
|
int accepted_fd; \
|
||||||
|
int blocking;
|
||||||
|
|
||||||
|
|
||||||
/* UV_TCP */
|
/* UV_TCP */
|
||||||
|
|||||||
13
include/uv.h
13
include/uv.h
@ -626,7 +626,18 @@ struct uv_tty_s {
|
|||||||
UV_TTY_PRIVATE_FIELDS
|
UV_TTY_PRIVATE_FIELDS
|
||||||
};
|
};
|
||||||
|
|
||||||
int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd);
|
/*
|
||||||
|
* Initialize a new TTY stream with the given file descriptor. Usually the
|
||||||
|
* file descriptor will be
|
||||||
|
* 0 = stdin
|
||||||
|
* 1 = stdout
|
||||||
|
* 2 = stderr
|
||||||
|
* The last argument, readable, specifies if you plan on calling
|
||||||
|
* uv_read_start with this stream. stdin is readable, stdout is not.
|
||||||
|
*
|
||||||
|
* TTY streams which are not readable have blocking writes.
|
||||||
|
*/
|
||||||
|
int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd, int readable);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set mode. 0 for normal, 1 for raw.
|
* Set mode. 0 for normal, 1 for raw.
|
||||||
|
|||||||
@ -53,6 +53,7 @@ void uv__stream_init(uv_loop_t* loop,
|
|||||||
uv_stream_t* stream,
|
uv_stream_t* stream,
|
||||||
uv_handle_type type) {
|
uv_handle_type type) {
|
||||||
uv__handle_init(loop, (uv_handle_t*)stream, type);
|
uv__handle_init(loop, (uv_handle_t*)stream, type);
|
||||||
|
loop->counters.stream_init++;
|
||||||
|
|
||||||
stream->alloc_cb = NULL;
|
stream->alloc_cb = NULL;
|
||||||
stream->close_cb = NULL;
|
stream->close_cb = NULL;
|
||||||
@ -83,7 +84,7 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
|
|||||||
assert(fd >= 0);
|
assert(fd >= 0);
|
||||||
stream->fd = fd;
|
stream->fd = fd;
|
||||||
|
|
||||||
((uv_handle_t*)stream)->flags |= flags;
|
stream->flags |= flags;
|
||||||
|
|
||||||
/* Reuse the port address if applicable. */
|
/* Reuse the port address if applicable. */
|
||||||
yes = 1;
|
yes = 1;
|
||||||
|
|||||||
@ -33,10 +33,19 @@ static int orig_termios_fd = -1;
|
|||||||
static struct termios orig_termios;
|
static struct termios orig_termios;
|
||||||
|
|
||||||
|
|
||||||
int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd) {
|
int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
|
||||||
uv__nonblock(fd, 1);
|
|
||||||
uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY);
|
uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY);
|
||||||
uv__stream_open((uv_stream_t*)tty, fd, UV_READABLE | UV_WRITABLE);
|
|
||||||
|
if (readable) {
|
||||||
|
uv__nonblock(fd, 1);
|
||||||
|
uv__stream_open((uv_stream_t*)tty, fd, UV_READABLE);
|
||||||
|
} else {
|
||||||
|
/* Note: writable tty we set to blocking mode. */
|
||||||
|
uv__nonblock(fd, 0);
|
||||||
|
uv__stream_open((uv_stream_t*)tty, fd, UV_WRITABLE);
|
||||||
|
tty->blocking = 1;
|
||||||
|
}
|
||||||
|
|
||||||
loop->counters.tty_init++;
|
loop->counters.tty_init++;
|
||||||
tty->mode = 0;
|
tty->mode = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -86,7 +86,7 @@ void uv_console_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd) {
|
int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd, int readable) {
|
||||||
HANDLE win_handle;
|
HANDLE win_handle;
|
||||||
CONSOLE_SCREEN_BUFFER_INFO info;
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ TEST_IMPL(tty) {
|
|||||||
*/
|
*/
|
||||||
ASSERT(UV_TTY == uv_guess_handle(0));
|
ASSERT(UV_TTY == uv_guess_handle(0));
|
||||||
|
|
||||||
r = uv_tty_init(uv_default_loop(), &tty, 0);
|
r = uv_tty_init(uv_default_loop(), &tty, 0, 1);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
r = uv_tty_get_winsize(&tty, &width, &height);
|
r = uv_tty_get_winsize(&tty, &width, &height);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user