Skip to content

Commit

Permalink
win: fix WriteFile() error translation (libuv#4562)
Browse files Browse the repository at this point in the history
Translate `ERROR_BROKEN_PIPE` and `ERROR_NO_DATA` to `UV_EPIPE` instead
of their default translation, which will be used for the rest of cases.

Refs: libuv#4548 (comment)
  • Loading branch information
santigimeno authored Oct 3, 2024
1 parent 65e3735 commit 473dafc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/win/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,12 @@ int uv_translate_sys_error(int sys_errno) {
default: return UV_UNKNOWN;
}
}

int uv_translate_write_sys_error(int sys_errno) {
switch (sys_errno) {
case ERROR_BROKEN_PIPE: return UV_EPIPE;
case ERROR_NO_DATA: return UV_EPIPE;
default:
return uv_translate_sys_error(sys_errno);
}
}
2 changes: 1 addition & 1 deletion src/win/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ void fs__write(uv_fs_t* req) {
error = ERROR_INVALID_FLAGS;
}

SET_REQ_WIN32_ERROR(req, error);
SET_REQ_UV_ERROR(req, uv_translate_write_sys_error(error), error);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/win/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,6 @@ void uv__wake_all_loops(void);
*/
void uv__init_detect_system_wakeup(void);

int uv_translate_write_sys_error(int sys_errno);

#endif /* UV_WIN_INTERNAL_H_ */
4 changes: 2 additions & 2 deletions src/win/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int uv_write(uv_write_t* req,
case UV_NAMED_PIPE:
err = uv__pipe_write(
loop, req, (uv_pipe_t*) handle, bufs, nbufs, NULL, cb);
break;
return uv_translate_write_sys_error(err);
case UV_TTY:
err = uv__tty_write(loop, req, (uv_tty_t*) handle, bufs, nbufs, cb);
break;
Expand Down Expand Up @@ -164,7 +164,7 @@ int uv_write2(uv_write_t* req,

err = uv__pipe_write(
loop, req, (uv_pipe_t*) handle, bufs, nbufs, send_handle, cb);
return uv_translate_sys_error(err);
return uv_translate_write_sys_error(err);
}


Expand Down

0 comments on commit 473dafc

Please sign in to comment.