From 9b8cef442874334fed4472701897ce20fb3970d8 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sun, 11 Jan 2015 23:30:00 +0100 Subject: [PATCH] win,tcp: support uv_try_write MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR: https://github.com/libuv/libuv/pull/127 Reviewed-by: Saúl Ibarra Corretgé --- src/win/internal.h | 2 ++ src/win/stream.c | 1 + src/win/tcp.c | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/win/internal.h b/src/win/internal.h index 89290aea..c89daa58 100644 --- a/src/win/internal.h +++ b/src/win/internal.h @@ -136,6 +136,8 @@ int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb); int uv_tcp_write(uv_loop_t* loop, uv_write_t* req, uv_tcp_t* handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb); +int uv__tcp_try_write(uv_tcp_t* handle, const uv_buf_t bufs[], + unsigned int nbufs); void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, uv_req_t* req); void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle, diff --git a/src/win/stream.c b/src/win/stream.c index 7665fb24..58773f00 100644 --- a/src/win/stream.c +++ b/src/win/stream.c @@ -191,6 +191,7 @@ int uv_try_write(uv_stream_t* stream, switch (stream->type) { case UV_TCP: + return uv__tcp_try_write((uv_tcp_t*) stream, bufs, nbufs); case UV_TTY: case UV_NAMED_PIPE: return UV_EAGAIN; diff --git a/src/win/tcp.c b/src/win/tcp.c index cff2929e..c5ddbed0 100644 --- a/src/win/tcp.c +++ b/src/win/tcp.c @@ -876,6 +876,30 @@ int uv_tcp_write(uv_loop_t* loop, } +int uv__tcp_try_write(uv_tcp_t* handle, + const uv_buf_t bufs[], + unsigned int nbufs) { + int result; + DWORD bytes; + + if (handle->write_reqs_pending > 0) + return UV_EAGAIN; + + result = WSASend(handle->socket, + (WSABUF*) bufs, + nbufs, + &bytes, + 0, + NULL, + NULL); + + if (result == SOCKET_ERROR) + return uv_translate_sys_error(WSAGetLastError()); + else + return bytes; +} + + void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, uv_req_t* req) { DWORD bytes, flags, err;