X-Git-Url: http://git.pond.sub.org/?p=empserver;a=blobdiff_plain;f=src%2Flib%2Fempthread%2Fio.c;h=47a2b1093e4de2a9cdb188131270077a7e4e276a;hp=ef285a74c4a67f1104b8339e9e70a83e43527a88;hb=904822e3;hpb=8549efbc1904e377c05e385844fe1adada61d573 diff --git a/src/lib/empthread/io.c b/src/lib/empthread/io.c index ef285a74c..47a2b1093 100644 --- a/src/lib/empthread/io.c +++ b/src/lib/empthread/io.c @@ -108,7 +108,16 @@ io_open(int fd, int flags, int bufsize, struct timeval timeout) void io_close(struct iop *iop) { - + char buf[IO_BUFSIZE]; + int ret; + + while (io_output(iop, 1) > 0) ; + shutdown(iop->fd, SHUT_WR); + while (empth_select(iop->fd, EMPTH_FD_READ, &iop->input_timeout) > 0) { + ret = read(iop->fd, buf, sizeof(buf)); + if (ret <= 0) + break; + } if (iop->input) ioq_destroy(iop->input); if (iop->output) @@ -201,15 +210,15 @@ io_output(struct iop *iop, int wait) if (wait) ef_make_stale(); - if (!ioq_qsize(iop->output)) - return 0; - if ((iop->flags & IO_WRITE) == 0) return -1; if (iop->flags & IO_ERROR) return -1; + if (!ioq_qsize(iop->output)) + return 0; + if (wait) { res = empth_select(iop->fd, EMPTH_FD_WRITE, NULL); if (res == 0)