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

(io_callout): Added an argument, the number of seconds

until the callout should be invoked.

Rev: src/io.c:1.158
Rev: src/io.h:1.87
parent 8f38a128
...@@ -280,7 +280,7 @@ lsh_oop_register_callout(struct lsh_callout *callout) ...@@ -280,7 +280,7 @@ lsh_oop_register_callout(struct lsh_callout *callout)
{ {
assert(source); assert(source);
if (callout->super.alive) if (callout->super.alive)
source->on_time(source, OOP_TIME_NOW, lsh_oop_time_callback, callout); source->on_time(source, callout->when, lsh_oop_time_callback, callout);
} }
static void static void
...@@ -288,7 +288,7 @@ lsh_oop_cancel_callout(struct lsh_callout *callout) ...@@ -288,7 +288,7 @@ lsh_oop_cancel_callout(struct lsh_callout *callout)
{ {
assert(source); assert(source);
if (callout->super.alive) if (callout->super.alive)
source->cancel_time(source, OOP_TIME_NOW, lsh_oop_time_callback, callout); source->cancel_time(source, callout->when, lsh_oop_time_callback, callout);
} }
...@@ -308,6 +308,7 @@ lsh_oop_cancel_callout(struct lsh_callout *callout) ...@@ -308,6 +308,7 @@ lsh_oop_cancel_callout(struct lsh_callout *callout)
(name lsh_callout) (name lsh_callout)
(super resource) (super resource)
(vars (vars
(when . "struct timeval")
(action object lsh_callback))) (action object lsh_callback)))
*/ */
...@@ -353,15 +354,25 @@ do_kill_callout(struct resource *s) ...@@ -353,15 +354,25 @@ do_kill_callout(struct resource *s)
} }
} }
/* Delays not implemented. */
struct resource * struct resource *
io_callout(struct lsh_callback *action) io_callout(struct lsh_callback *action, unsigned seconds)
{ {
NEW(lsh_callout, self); NEW(lsh_callout, self);
init_resource(&self->super, do_kill_callout); init_resource(&self->super, do_kill_callout);
if (seconds)
{
/* NOTE: Using absolute times, like oop does, is a little
* dangerous if the system time is changed abruptly. */
if (gettimeofday(&self->when, NULL) < 0)
fatal("io_callout: gettimeofday failed!\n");
self->when.tv_sec += seconds;
}
else
self->when = OOP_TIME_NOW;
self->action = action; self->action = action;
lsh_oop_register_callout(self); lsh_oop_register_callout(self);
gc_global(&self->super); gc_global(&self->super);
...@@ -398,7 +409,7 @@ do_buffered_read(struct io_callback *s, ...@@ -398,7 +409,7 @@ do_buffered_read(struct io_callback *s,
case EPIPE: case EPIPE:
/* Getting EPIPE from read seems strange, but appearantly /* Getting EPIPE from read seems strange, but appearantly
* it happens sometimes. */ * it happens sometimes. */
werror("Unexpected EPIPE.\n"); werror("Unexpected EPIPE from read.\n");
default: default:
EXCEPTION_RAISE(fd->e, EXCEPTION_RAISE(fd->e,
make_io_exception(EXC_IO_READ, fd, make_io_exception(EXC_IO_READ, fd,
......
...@@ -234,7 +234,7 @@ io_signal_handler(int signum, ...@@ -234,7 +234,7 @@ io_signal_handler(int signum,
struct lsh_callback *action); struct lsh_callback *action);
struct resource * struct resource *
io_callout(struct lsh_callback *action); io_callout(struct lsh_callback *action, unsigned seconds);
int blocking_read(int fd, struct read_handler *r); int blocking_read(int fd, struct read_handler *r);
......
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