1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-25 07:50:27 +00:00

Return an error message if writes fail. Address #462.

This commit is contained in:
Calvin Rose 2020-08-10 11:01:57 -05:00
parent c903e49a4f
commit 6f2f3fdb68
2 changed files with 10 additions and 2 deletions

View File

@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
## Unreleased - ???
- Update meson build script to fix bug on Debian's version of meson
- Add `xprint`, `xprin`, `xprintf`, and `xprinf`.
- `net/write` now returns an error message if write fails.
- Fix issue with SIGPIPE on macOS and BSDs.
## 1.11.3 - 2020-08-03
- Add `JANET_HASHSEED` environment variable when `JANET_PRF` is enabled.

View File

@ -350,6 +350,12 @@ static size_t janet_loop_event(size_t index) {
if (nwrote > 0) {
start += nwrote;
} else {
if (nwrote == -1) {
const uint8_t *msg = janet_formatc("write error: %s", strerror(JLASTERR));
resumeval = janet_wrap_string(msg);
} else {
resumeval = janet_cstringv("could not write");
}
start = len;
}
}
@ -637,7 +643,7 @@ static const JanetReg net_cfuns[] = {
JDOC("(net/read stream nbytes &opt buf)\n\n"
"Read up to n bytes from a stream, suspending the current fiber until the bytes are available. "
"If less than n bytes are available (and more than 0), will push those bytes and return early. "
"Returns a buffer with up to n more bytes in it.")
"Returns a buffer with up to n more bytes in it, or nil if the read failed.")
},
{
"net/chunk", cfun_stream_chunk,
@ -648,7 +654,7 @@ static const JanetReg net_cfuns[] = {
"net/write", cfun_stream_write,
JDOC("(net/write stream data)\n\n"
"Write data to a stream, suspending the current fiber until the write "
"completes. Returns stream.")
"completes. Returns nil, or an error message if the write failed.")
},
{
"net/close", cfun_stream_close,