12 iointerrupt(Ioproc *io)
16 fprint(2, "bug: cannot iointerrupt %p yet\n", io);
24 threadsetname("ioproc");
27 * first recvp acquires the ioproc.
28 * second tells us that the data is ready.
31 while(recv(io->c, &x) == -1)
33 if(x == 0) /* our cue to leave */
37 /* caller is now committed -- even if interrupted he'll return */
38 while(recv(io->creply, &x) == -1)
40 if(x == 0) /* caller backed out */
44 io->ret = io->op(&io->arg);
46 rerrstr(io->err, sizeof io->err);
47 while(send(io->creply, &io) == -1)
49 while(recv(io->creply, &x) == -1)
59 io = mallocz(sizeof(*io), 1);
61 sysfatal("ioproc malloc: %r");
62 io->c = chancreate(sizeof(void*), 0);
63 chansetname(io->c, "ioc%p", io->c);
64 io->creply = chancreate(sizeof(void*), 0);
65 chansetname(io->creply, "ior%p", io->c);
66 io->tid = proccreate(xioproc, io, STACK);
71 closeioproc(Ioproc *io)
76 while(send(io->c, 0) == -1)
84 iocall(Ioproc *io, long (*op)(va_list*), ...)
90 if(send(io->c, &io) == -1){
91 werrstr("interrupted");
97 va_start(io->arg, op);
100 while(send(io->creply, &msg) == -1){
105 werrstr("interrupted");
110 * If we get interrupted, we have stick around so that
111 * the IO proc has someone to talk to. Send it an interrupt
115 while(recv(io->creply, nil) == -1){
123 strecpy(e, e+sizeof e, io->err);
126 /* release resources */
127 while(send(io->creply, &io) == -1)