From: Fredrik Tolf Date: Fri, 20 Aug 2010 15:44:56 +0000 (+0200) Subject: Always send the entire buffer in mtwrite. X-Git-Tag: 0.1~97 X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=commitdiff_plain;h=9dc25d3d8337f3e9ecc31530f3be10b9ecf07422 Always send the entire buffer in mtwrite. If not, then libc considers it an error, as with the fwrite(3) protocol. That does, however, seem to violate what is specified in the manual, which states that mtwrite should work like write(2). --- diff --git a/lib/mtio.c b/lib/mtio.c index c861261..1727d43 100644 --- a/lib/mtio.c +++ b/lib/mtio.c @@ -161,28 +161,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)