Skip to content

Commit

Permalink
win, tcp: avoid starving the loop
Browse files Browse the repository at this point in the history
Limit the time a TCP read callback can be called on a single loop
iteration to 32.

Ref: libuv@738b31e
Fixes: libuv#2027
PR-URL: libuv#2049
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
bzoz committed Nov 1, 2018
1 parent 6dd44ca commit 8a647d4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/win/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_req_t* req) {
DWORD bytes, flags, err;
uv_buf_t buf;
int count;

assert(handle->type == UV_TCP);

Expand Down Expand Up @@ -999,7 +1000,8 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
}

/* Do nonblocking reads until the buffer is empty */
while (handle->flags & UV_HANDLE_READING) {
count = 32;
while ((handle->flags & UV_HANDLE_READING) && (count-- > 0)) {
buf = uv_buf_init(NULL, 0);
handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);
if (buf.base == NULL || buf.len == 0) {
Expand Down

0 comments on commit 8a647d4

Please sign in to comment.