Skip to content

Commit

Permalink
win,tty: support uv_try_write
Browse files Browse the repository at this point in the history
All windows console writes are synchronous anyway, so there's no reason
for uv_try_write() to do nothing.

PR: #127
Reviewed-by: Saúl Ibarra Corretgé <[email protected]>
  • Loading branch information
piscisaureus committed Jan 13, 2015
1 parent 85a2934 commit 55ea371
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/win/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ int uv_tty_read_start(uv_tty_t* handle, uv_alloc_cb alloc_cb,
int uv_tty_read_stop(uv_tty_t* handle);
int uv_tty_write(uv_loop_t* loop, uv_write_t* req, uv_tty_t* handle,
const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb);
int uv__tty_try_write(uv_tty_t* handle, const uv_buf_t bufs[],
unsigned int nbufs);
void uv_tty_close(uv_tty_t* handle);

void uv_process_tty_read_req(uv_loop_t* loop, uv_tty_t* handle,
Expand Down
1 change: 1 addition & 0 deletions src/win/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ int uv_try_write(uv_stream_t* stream,
case UV_TCP:
return uv__tcp_try_write((uv_tcp_t*) stream, bufs, nbufs);
case UV_TTY:
return uv__tty_try_write((uv_tty_t*) stream, bufs, nbufs);
case UV_NAMED_PIPE:
return UV_EAGAIN;
default:
Expand Down
15 changes: 15 additions & 0 deletions src/win/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,21 @@ int uv_tty_write(uv_loop_t* loop,
}


int uv__tty_try_write(uv_tty_t* handle,
const uv_buf_t bufs[],
unsigned int nbufs) {
DWORD error;

if (handle->write_reqs_pending > 0)
return UV_EAGAIN;

if (uv_tty_write_bufs(handle, bufs, nbufs, &error))
return uv_translate_sys_error(error);

return uv__count_bufs(bufs, nbufs);
}


void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle,
uv_write_t* req) {
int err;
Expand Down

0 comments on commit 55ea371

Please sign in to comment.