1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 01:37:19 +00:00

When reading from a stream, EPIPE is considered EOS.

Before, EPIPE caused an error, but in most cases it is better
to consider it an end of stream. In the future, we may want to allow
cusomtization of this behavior with flags on the stream but for now
let's keep it simpler.
This commit is contained in:
Calvin Rose 2020-11-16 16:42:09 -06:00
parent 760e4e3d68
commit 078f50d45a
2 changed files with 11 additions and 3 deletions

View File

@ -2,6 +2,7 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## Unreleased - ??? ## Unreleased - ???
- Add `upscope` special form.
- `os/execute` and `os/spawn` can take streams for redirecting IO. - `os/execute` and `os/spawn` can take streams for redirecting IO.
- Add `;parser` and `:read` parameters to `run-context`. - Add `;parser` and `:read` parameters to `run-context`.
- Add `os/open` if ev is enabled. - Add `os/open` if ev is enabled.

View File

@ -1317,9 +1317,16 @@ JanetAsyncStatus ev_machine_read(JanetListenerState *s, JanetAsyncEvent event) {
/* Check for errors - special case errors that can just be waited on to fix */ /* Check for errors - special case errors that can just be waited on to fix */
if (nread == -1) { if (nread == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) break; if (errno == EAGAIN || errno == EWOULDBLOCK) {
janet_cancel(s->fiber, janet_ev_lasterr()); return JANET_ASYNC_STATUS_NOT_DONE;
return JANET_ASYNC_STATUS_DONE; }
/* In stream protocols, a pipe error is end of stream */
if (errno == EPIPE && (state->mode != JANET_ASYNC_READMODE_RECVFROM)) {
nread = 0;
} else {
janet_cancel(s->fiber, janet_ev_lasterr());
return JANET_ASYNC_STATUS_DONE;
}
} }
/* Only allow 0-length packets in recv-from. In stream protocols, a zero length packet is EOS. */ /* Only allow 0-length packets in recv-from. In stream protocols, a zero length packet is EOS. */