Commit 1fca65f4 authored by Niels Möller's avatar Niels Möller

* src/io.c (lsh_signal_handler): New class.

(lsh_callout): Renamed the callout class, and made it inherit
resource.
(io_iter): Call signal handlers.
(make_io_backend): New function.
(init_backend): Deleted function.
(io_signal_handler): New function.
(io_callout): New function.
(init_file): Use resource_init().

Rev: src/io.c:1.117
parent 9805d2c2
......@@ -67,6 +67,45 @@
#include "io.c.x"
/* Calls trigged by a signal handler. */
/* GABA:
(class
(name lsh_signal_handler)
(super resource)
(vars
(next object lsh_signal_handler)
(flag . "sig_atomic_t *")
(action object lsh_callback)))
*/
/* Scheduled calls. FIXME: For now, no scheduling in time. */
/* GABA:
(class
(name lsh_callout)
(super resource)
(vars
(next object lsh_callout)
(action object lsh_callback)))
;; (when . time_t)
*/
/* GABA:
(class
(name io_backend)
(vars
; Linked list of fds.
(files object lsh_fd)
; Stack of closed files
;; (closed object lsh_fd)
; Flags
(signals object lsh_signal_handler)
; Callouts
(callouts object lsh_callout)))
*/
/* Backend loop */
......@@ -85,18 +124,40 @@ int io_iter(struct io_backend *b)
/* int timeout; */
int res;
/* Check all flags */
if (b->signals)
{
struct lsh_signal_handler *f;
struct lsh_signal_handler **f_p;
for (f_p = &b->signals; (f = *f_p); )
{
if (!f->super.alive)
*f_p = f->next;
else
{
if (*f->flag)
{
*f->flag = 0;
LSH_CALLBACK(f->action);
}
f_p = &f->next;
}
}
}
/* Invoke all callouts. Clear the list first; if any callout
* installs another one, that will not be invoked until the next
* iteration. */
if (b->callouts)
{
struct callout *p = b->callouts;
b->callouts = NULL;
struct lsh_callout *p;
while (p)
for (p = b->callouts, b->callouts = NULL;
p; p = p->next)
if (p->super.alive)
{
LSH_CALLBACK(p->action);
p = p->next;
p->super.alive = 0;
}
}
......@@ -324,7 +385,8 @@ int io_iter(struct io_backend *b)
}
void io_run(struct io_backend *b)
void
io_run(struct io_backend *b)
{
struct sigaction pipe;
memset(&pipe, 0, sizeof(pipe));
......@@ -340,12 +402,50 @@ void io_run(struct io_backend *b)
;
}
void init_backend(struct io_backend *b)
struct io_backend *
make_io_backend(void)
{
NEW(io_backend, b);
b->files = NULL;
b->signals = NULL;
b->callouts = NULL;
return b;
}
struct resource *
io_signal_handler(struct io_backend *b,
sig_atomic_t *flag,
struct lsh_callback *action)
{
NEW(lsh_signal_handler, handler);
resource_init(&handler->super, NULL);
handler->next = b->signals;
handler->flag = flag;
handler->action = action;
b->signals = handler;
return &handler->super;
}
/* Delays not implemented. */
struct resource *
io_callout(struct io_backend *b,
UINT32 delay UNUSED,
struct lsh_callback *action)
{
NEW(lsh_callout, callout);
resource_init(&callout->super, NULL);
callout->next = b->callouts;
callout->action = action;
b->callouts = callout;
return &callout->super;
}
/* Read-related callbacks */
......@@ -767,6 +867,8 @@ static void
init_file(struct io_backend *b, struct lsh_fd *f, int fd,
struct exception_handler *e)
{
resource_init(&f->super, do_kill_fd);
f->fd = fd;
f->e = make_exception_handler(do_exc_io_handler, e, HANDLER_CONTEXT);
......@@ -782,9 +884,6 @@ init_file(struct io_backend *b, struct lsh_fd *f, int fd,
f->write = NULL;
f->write_close = NULL;
f->super.alive = 1;
f->super.kill = do_kill_fd;
f->next = b->files;
b->files = f;
}
......
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