X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fmtio.c;h=4211996eb698b2e69ba1c9d82f387d61e73c3515;hb=4d7cf6cba43bf1dc072b571d1b62cf214d9a7a10;hp=c861261d6c44ffa4272bbfb974087181936e666e;hpb=e1cdf02ebc900813c2395c58ee528440a9699e18;p=ashd.git diff --git a/lib/mtio.c b/lib/mtio.c index c861261..4211996 100644 --- a/lib/mtio.c +++ b/lib/mtio.c @@ -66,6 +66,7 @@ int block(int fd, int ev, time_t to) bl->p->n = bl->n; if(bl == blockers) blockers = bl->n; + free(bl); return(rv); } @@ -161,28 +162,35 @@ static ssize_t mtwrite(void *cookie, const char *buf, size_t len) { struct stdiofd *d = cookie; int ev; + size_t off; ssize_t ret; - while(1) { + off = 0; + while(off < len) { if(d->sock) - ret = send(d->fd, buf, len, MSG_DONTWAIT | MSG_NOSIGNAL); + ret = send(d->fd, buf + off, len - off, MSG_DONTWAIT | MSG_NOSIGNAL); else - ret = write(d->fd, buf, len); - if((ret < 0) && (errno == EAGAIN)) { - ev = block(d->fd, EV_WRITE, d->timeout); - if(ev < 0) { - /* If we just go on, we should get the real error. */ - continue; - } else if(ev == 0) { - errno = ETIMEDOUT; - return(-1); + ret = write(d->fd, buf + off, len - off); + if(ret < 0) { + if(errno == EAGAIN) { + ev = block(d->fd, EV_WRITE, d->timeout); + if(ev < 0) { + /* If we just go on, we should get the real error. */ + continue; + } else if(ev == 0) { + errno = ETIMEDOUT; + return(off); + } else { + continue; + } } else { - continue; + return(off); } } else { - return(ret); + off += ret; } } + return(off); } static int mtclose(void *cookie)