aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jim-aio.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/jim-aio.c b/jim-aio.c
index 4c59e1d..e25af18 100644
--- a/jim-aio.c
+++ b/jim-aio.c
@@ -194,9 +194,17 @@ typedef struct AioFile
Jim_Obj *writebuf; /* Contains any buffered write data. refcount=1 */
} AioFile;
+static void aio_consume(Jim_Obj *objPtr, int n);
+
static int stdio_writer(struct AioFile *af, const char *buf, int len)
{
- return write(af->fd, buf, len);
+ int ret = write(af->fd, buf, len);
+ if (ret < 0 && errno == EPIPE) {
+ /* Also discard the write buffer since otherwise when
+ * we try to flush on shutdown we may get SIGPIPE */
+ aio_consume(af->writebuf, Jim_Length(af->writebuf));
+ }
+ return ret;
}
static int stdio_reader(struct AioFile *af, char *buf, int len, int nb)