12 iointerrupt(Ioproc *io)
16 fprint(2, "bug: cannot iointerrupt yet\n");
25 * first recvp acquires the ioproc.
26 * second tells us that the data is ready.
29 while(recv(io->c, &x) == -1)
31 if(x == 0) /* our cue to leave */
35 /* caller is now committed -- even if interrupted he'll return */
36 while(recv(io->creply, &x) == -1)
38 if(x == 0) /* caller backed out */
42 io->ret = io->op(&io->arg);
44 rerrstr(io->err, sizeof io->err);
45 while(send(io->creply, &io) == -1)
47 while(recv(io->creply, &x) == -1)
57 io = mallocz(sizeof(*io), 1);
59 sysfatal("ioproc malloc: %r");
60 io->c = chancreate(sizeof(void*), 0);
61 chansetname(io->c, "ioc%p", io->c);
62 io->creply = chancreate(sizeof(void*), 0);
63 chansetname(io->creply, "ior%p", io->c);
64 io->tid = proccreate(xioproc, io, STACK);
69 closeioproc(Ioproc *io)
74 while(send(io->c, 0) == -1)
82 iocall(Ioproc *io, long (*op)(va_list*), ...)
88 if(send(io->c, &io) == -1){
89 werrstr("interrupted");
95 va_start(io->arg, op);
98 while(send(io->creply, &msg) == -1){
103 werrstr("interrupted");
108 * If we get interrupted, we have stick around so that
109 * the IO proc has someone to talk to. Send it an interrupt
113 while(recv(io->creply, nil) == -1){
121 strecpy(e, e+sizeof e, io->err);
124 /* release resources */
125 while(send(io->creply, &io) == -1)