Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Add uv_try_write on windows #1464

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/win/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/win/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +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 */
switch (stream->type) {
case UV_TCP:
return uv_tcp_try_write((uv_tcp_t*) stream, bufs, nbufs);
break;
default:
break;
}
return UV_ENOSYS;
}

Expand Down
16 changes: 16 additions & 0 deletions src/win/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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*) handle)->socket,
(WSABUF*) bufs,
nbufs,
&bytes,
0,
NULL,
NULL) == 0)
return (int) bytes;
return uv_translate_sys_error(WSAGetLastError());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be returning some sort of EAGAIN if WSAGetLastError() is WSAEWOULDBLOCK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not only, we also need to return it if there are other write requests pending. That's why I we need to wait for #1439.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be returning some sort of EAGAIN if WSAGetLastError() is WSAEWOULDBLOCK.

Does uv_translate_sys_error not do this?

Not only, we also need to return it if there are other write requests pending. That's why I we need to wait for #1439.

It would be possible to just look at the write_reqs_pending field and check if there are pending overlapped requests. That seems like a simple addition to this patch which would make it correct.

unsigned int write_reqs_pending; \

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be possible to just look at the write_reqs_pending

Just like we do on linux.

}


void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_req_t* req) {
DWORD bytes, flags, err;
Expand Down
12 changes: 0 additions & 12 deletions test/test-tcp-try-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -138,5 +128,3 @@ TEST_IMPL(tcp_try_write) {
MAKE_VALGRIND_HAPPY();
return 0;
}

#endif /* !_WIN32 */