Blob
1 #include "threadimpl.h"3 long4 iocall(Ioproc *io, long (*op)(va_list*), ...)5 {6 char e[ERRMAX];7 int ret, inted;8 Ioproc *msg;10 if(send(io->c, &io) == -1){11 werrstr("interrupted");12 return -1;13 }14 assert(!io->inuse);15 io->inuse = 1;16 io->op = op;17 va_start(io->arg, op);18 msg = io;19 inted = 0;20 while(send(io->creply, &msg) == -1){21 msg = nil;22 inted = 1;23 }24 if(inted){25 werrstr("interrupted");26 return -1;27 }29 /*30 * If we get interrupted, we have stick around so that31 * the IO proc has someone to talk to. Send it an interrupt32 * and try again.33 */34 inted = 0;35 while(recv(io->creply, nil) == -1){36 inted = 1;37 iointerrupt(io);38 }39 USED(inted);40 va_end(io->arg);41 ret = io->ret;42 if(ret < 0)43 strecpy(e, e+sizeof e, io->err);44 io->inuse = 0;46 /* release resources */47 while(send(io->creply, &io) == -1)48 ;49 if(ret < 0)50 errstr(e, sizeof e);51 return ret;52 }