From f7fd6b30fdc0c00bfc13960609e5a49a979272fb Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 9 Sep 2014 12:22:36 +0900 Subject: [PATCH 1/4] Add uv_try_write on windows --- src/win/internal.h | 1 + src/win/stream.c | 9 +++++++-- src/win/tcp.c | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/win/internal.h b/src/win/internal.h index d7aae53e64..ab88373879 100644 --- a/src/win/internal.h +++ b/src/win/internal.h @@ -155,6 +155,7 @@ int uv_tcp_import(uv_tcp_t* tcp, uv__ipc_socket_info_ex* socket_info_ex, int uv_tcp_duplicate_socket(uv_tcp_t* handle, int pid, LPWSAPROTOCOL_INFOW protocol_info); +int uv_tcp_try_write(uv_tcp_t* handle, const uv_buf_t bufs[], unsigned int nbufs); /* * UDP diff --git a/src/win/stream.c b/src/win/stream.c index 057f72ecad..b142716557 100644 --- a/src/win/stream.c +++ b/src/win/stream.c @@ -184,8 +184,13 @@ int uv_write2(uv_write_t* req, int uv_try_write(uv_stream_t* stream, const uv_buf_t bufs[], unsigned int nbufs) { - /* NOTE: Won't work with overlapped writes */ - return UV_ENOSYS; + switch (stream->type) { + case UV_TCP: + return uv_tcp_try_write((uv_tcp_t*) stream, bufs, nbufs); + break; + default: + assert(0); + } } diff --git a/src/win/tcp.c b/src/win/tcp.c index 23fadc220d..641b7b7b2a 100644 --- a/src/win/tcp.c +++ b/src/win/tcp.c @@ -876,6 +876,22 @@ 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) { + DWORD bytes = 0; + if (WSASend(((uv_tcp_t*)stream)->socket, + (WSABUF*) bufs, + nbufs, + &bytes, + 0, + NULL, + NULL) == 0) + return (int) bytes; + return uv_translate_sys_error(WSAGetLastError()); +} + + void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, uv_req_t* req) { DWORD bytes, flags, err; From fa2c126723cd7569c7c032001c5aadd4ea155993 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 9 Sep 2014 12:37:42 +0900 Subject: [PATCH 2/4] Enable test for uv_try_write on windows --- test/test-tcp-try-write.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/test-tcp-try-write.c b/test/test-tcp-try-write.c index baff6cf36c..8a60136b64 100644 --- a/test/test-tcp-try-write.c +++ b/test/test-tcp-try-write.c @@ -28,16 +28,6 @@ #define MAX_BYTES 1024 * 1024 -#ifdef _WIN32 - -TEST_IMPL(tcp_try_write) { - - MAKE_VALGRIND_HAPPY(); - return 0; -} - -#else /* !_WIN32 */ - static uv_tcp_t server; static uv_tcp_t client; static uv_tcp_t incoming; @@ -138,5 +128,3 @@ TEST_IMPL(tcp_try_write) { MAKE_VALGRIND_HAPPY(); return 0; } - -#endif /* !_WIN32 */ From 26827d3f3fb33dfadde2ca683a88a765ba6ae618 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 9 Sep 2014 12:44:06 +0900 Subject: [PATCH 3/4] Fix build --- src/win/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win/tcp.c b/src/win/tcp.c index 641b7b7b2a..540c97f491 100644 --- a/src/win/tcp.c +++ b/src/win/tcp.c @@ -880,7 +880,7 @@ int uv_tcp_try_write(uv_tcp_t* handle, const uv_buf_t bufs[], unsigned int nbufs) { DWORD bytes = 0; - if (WSASend(((uv_tcp_t*)stream)->socket, + if (WSASend(((uv_tcp_t*) handle)->socket, (WSABUF*) bufs, nbufs, &bytes, From c20bb226e8b72f9150e5de69504bddf71aac52cd Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 9 Sep 2014 22:43:44 +0900 Subject: [PATCH 4/4] Return UV_ENOSYS --- src/win/stream.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/win/stream.c b/src/win/stream.c index b142716557..34aec49291 100644 --- a/src/win/stream.c +++ b/src/win/stream.c @@ -189,8 +189,9 @@ int uv_try_write(uv_stream_t* stream, return uv_tcp_try_write((uv_tcp_t*) stream, bufs, nbufs); break; default: - assert(0); + break; } + return UV_ENOSYS; }