Properly shutdown pipe writer when reader closes

This commit is contained in:
Mark
2020-07-24 14:35:08 +03:00
parent 277b65d329
commit 014463db5a
2 changed files with 8 additions and 3 deletions
+1 -3
View File
@@ -108,9 +108,7 @@ static ssize_t pipe_vnode_read(struct ofile *of, void *buf, size_t count) {
static void pipe_vnode_close(struct ofile *of) {
_assert(of && of->file.priv_data);
if (of->flags & OF_WRITABLE) {
ring_signal(of->file.priv_data, RING_SIGNAL_EOF);
}
ring_signal(of->file.priv_data, RING_SIGNAL_EOF);
// TODO: this
//kfree(((struct ring *) of->file.priv_data)->base);
//kfree(of->file.priv_data);
+7
View File
@@ -96,12 +96,18 @@ int ring_putc(struct thread *ctx, struct ring *ring, char c, int wait) {
if (wait) {
int res;
while (!ring_writable(ring)) {
if (ring->flags & RING_SIGNAL_EOF) {
return -EPIPE;
}
if ((res = thread_wait_io(ctx, &ring->writer_wait)) != 0) {
_assert(res == -EINTR);
return res;
}
}
}
if (ring->flags & RING_SIGNAL_EOF) {
return -EPIPE;
}
ring->base[ring->wr] = c;
ring_advance_write(ring);
@@ -122,6 +128,7 @@ int ring_write(struct thread *ctx, struct ring *ring, const void *buf, size_t le
void ring_signal(struct ring *r, int s) {
r->flags |= s;
thread_notify_io(&r->wait);
thread_notify_io(&r->writer_wait);
}
int ring_init(struct ring *r, size_t cap) {