Commit 5571f557 authored by Niels Möller's avatar Niels Möller

* io.c (blocking_read): New function.

Rev: src/io.c:1.42
Rev: src/io.h:1.27
parent 53691b93
...@@ -450,7 +450,31 @@ static void init_file(struct io_backend *b, struct lsh_fd *f, int fd) ...@@ -450,7 +450,31 @@ static void init_file(struct io_backend *b, struct lsh_fd *f, int fd)
f->next = b->files; f->next = b->files;
b->files = f; b->files = f;
} }
/* Blocking read from a file descriptor (i.e. don't use the backend).
* The fd should *not* be in non-blocking mode. */
int blocking_read(int fd, struct read_handler *handler)
{
struct fd_read r =
{ { STACK_HEADER, do_read }, fd };
while (1)
{
int res = READ_HANDLER(handler,
&r.super);
assert(!(res & (LSH_HOLD | LSH_KILL_OTHERS)));
if (res & (LSH_CLOSE | LSH_DIE))
{
close(fd);
return res;
}
if (res & LSH_FAIL)
werror("blocking_read: Ignoring error %d\n", res);
}
}
/* /*
* Fill in ADDR from HOST, SERVICE and PROTOCOL. * Fill in ADDR from HOST, SERVICE and PROTOCOL.
* Supplying a null pointer for HOST means use INADDR_ANY. * Supplying a null pointer for HOST means use INADDR_ANY.
......
...@@ -154,6 +154,8 @@ void init_backend(struct io_backend *b); ...@@ -154,6 +154,8 @@ void init_backend(struct io_backend *b);
int io_iter(struct io_backend *b); int io_iter(struct io_backend *b);
void io_run(struct io_backend *b); void io_run(struct io_backend *b);
int blocking_read(int fd, struct read_handler *r);
int get_inaddr(struct sockaddr_in * addr, int get_inaddr(struct sockaddr_in * addr,
const char * host, const char * host,
const char * service, const char * service,
......
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