Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* Lwt_react.S.l[2-6]_s used polymorphic equality which could cause errors when
handling functional values. (#893, Jérôme Vouillon)

* On Windows, treat ERROR_BROKEN_PIPE on read as zero-read instead
of error. See OCaml PR #4790. (#898, Antonin Décimo)

====== Additions ======

* Lwt_bytes.blit_from_string: string complement of Lwt_bytes.blit (#882, Hugo Heuzard).
Expand Down
7 changes: 6 additions & 1 deletion src/unix/windows_c/windows_bytes_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ CAMLprim value lwt_unix_bytes_read(value fd, value buf, value vofs, value vlen)
numbytes, &numwritten, NULL))
err = GetLastError();
}
if (err) {
if (err == ERROR_BROKEN_PIPE) {
/* The write handle for an anonymous pipe has been closed. We match
the Unix behavior, and treat this as a zero-read instead of a
Unix_error. See OCaml PR #4790. */
numwritten = 0;
} else if (err) {
win32_maperr(err);
uerror("write", Nothing);
}
Expand Down
7 changes: 6 additions & 1 deletion src/unix/windows_c/windows_bytes_read_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ static value result_bytes_read(struct job_bytes_read *job)
value result;
DWORD error = job->error_code;
caml_remove_generational_global_root(&job->ocaml_buffer);
if (error) {
if (error == ERROR_BROKEN_PIPE) {
/* The write handle for an anonymous pipe has been closed. We match the
Unix behavior, and treat this as a zero-read instead of a Unix_error.
See OCaml PR #4790. */
job->result = 0;
} else if (error) {
lwt_unix_free_job(&job->job);
win32_maperr(error);
uerror("bytes_read", Nothing);
Expand Down
7 changes: 6 additions & 1 deletion src/unix/windows_c/windows_pread.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ CAMLprim value lwt_unix_pread(value fd, value buf, value vfile_offset,
&overlapped))
err = GetLastError();
}
if (err) {
if (err == ERROR_BROKEN_PIPE) {
/* The write handle for an anonymous pipe has been closed. We match
the Unix behavior, and treat this as a zero-read instead of a
Unix_error. See OCaml PR #4790. */
numwritten = 0;
} else if (err) {
win32_maperr(err);
uerror("pread", Nothing);
}
Expand Down
7 changes: 6 additions & 1 deletion src/unix/windows_c/windows_pread_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ static value result_pread(struct job_pread *job)
{
value result;
DWORD error = job->error_code;
if (error) {
if (error == ERROR_BROKEN_PIPE) {
/* The write handle for an anonymous pipe has been closed. We match the
Unix behavior, and treat this as a zero-read instead of a Unix_error.
See OCaml PR #4790. */
job->result = 0;
} else if (error) {
caml_remove_generational_global_root(&job->string);
lwt_unix_free_job(&job->job);
win32_maperr(error);
Expand Down
7 changes: 6 additions & 1 deletion src/unix/windows_c/windows_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ CAMLprim value lwt_unix_read(value fd, value buf, value vofs, value vlen)
if (!ReadFile(h, &Byte(buf, ofs), numbytes, &numwritten, NULL))
err = GetLastError();
}
if (err) {
if (err == ERROR_BROKEN_PIPE) {
/* The write handle for an anonymous pipe has been closed. We match
the Unix behavior, and treat this as a zero-read instead of a
Unix_error. See OCaml PR #4790. */
numwritten = 0;
} else if (err) {
win32_maperr(err);
uerror("read", Nothing);
}
Expand Down
7 changes: 6 additions & 1 deletion src/unix/windows_c/windows_read_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ static value result_read(struct job_read *job)
{
value result;
DWORD error = job->error_code;
if (error) {
if (error == ERROR_BROKEN_PIPE) {
/* The write handle for an anonymous pipe has been closed. We match the
Unix behavior, and treat this as a zero-read instead of a Unix_error.
See OCaml PR #4790. */
job->result = 0;
} else if (error) {
caml_remove_generational_global_root(&job->string);
lwt_unix_free_job(&job->job);
win32_maperr(error);
Expand Down