Commit ced67145 authored by Niels Möller's avatar Niels Möller
Browse files

(close_fd_read): New function.

(do_buffered_read): Call close_fd_read on EOF. This stops reading
from the file, and also marks it for closing unless it has a write
callback.
(do_consuming_read): Likewise.

Rev: ChangeLog:1.308
Rev: src/io.c:1.125
Rev: src/io.h:1.73
parent 3a9fae40
2001-02-22 Niels Mller <nisse@ehand.com>
* src/io.c (close_fd_read): New function.
(do_buffered_read): Call close_fd_read on EOF. This stops reading
from the file, and also marks it for closing unless it has a write
callback.
(do_consuming_read): Likewise.
2001-02-21 Niels Mller <nisse@ehand.com>
* src/io.c (do_consuming_read): Added an assert do check that
......
......@@ -560,8 +560,8 @@ do_buffered_read(struct io_callback *s,
assert(fd->want_read);
assert(self->handler);
/* NOTE: We don't close the fd here, it's up to the read handler
* to do that if appropriate. */
/* Close the fd, unless it has a write callback. */
close_fd_read(fd);
READ_HANDLER(self->handler, 0, NULL);
}
......@@ -593,8 +593,7 @@ do_consuming_read(struct io_callback *c,
if (fd->hanged_up)
{
/* If hanged_up is set, pretend that read() returned 0 */
A_WRITE(self->consumer, NULL);
return;
goto eof;
}
if (!wanted)
......@@ -632,9 +631,9 @@ do_consuming_read(struct io_callback *c,
}
else
{
/* NOTE: We don't close the fd here, it's up to the read handler
* to do that if appropriate. */
eof:
/* Close the fd, unless it has a write callback. */
close_fd_read(fd);
A_WRITE(self->consumer, NULL);
}
}
......@@ -874,7 +873,8 @@ static void do_kill_fd(struct resource *r)
{
CAST_SUBTYPE(lsh_fd, fd, r);
/* FIXME: Should we use close_fd() or close_fd_nicely() ? */
/* We use close_fd_nicely, so that any data in the write buffer is
* flushed before the fd is closed. */
if (r->alive)
close_fd_nicely(fd);
}
......@@ -1768,6 +1768,16 @@ void close_fd_nicely(struct lsh_fd *fd)
kill_fd(fd);
}
/* Stop reading, but if the fd has a write callback, keep it open. */
void close_fd_read(struct lsh_fd *fd)
{
fd->want_read = 0;
fd->read = NULL;
if (!fd->write)
/* We won't be writing anything on this fd, so close it. */
kill_fd(fd);
}
/* Responsible for handling the EXC_FINISH_READ exception. It should
* be a parent to the connection related exception handlers, as for
......
......@@ -340,6 +340,9 @@ void close_fd(struct lsh_fd *fd);
* is completely written. */
void close_fd_nicely(struct lsh_fd *fd);
/* Stop reading, but if the fd has a write callback, keep it open. */
void close_fd_read(struct lsh_fd *fd);
struct lsh_fd *io_write_file(struct io_backend *backend,
const char *fname, int flags,
int mode,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment