From 9dc25d3d8337f3e9ecc31530f3be10b9ecf07422 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Fri, 20 Aug 2010 17:44:56 +0200 Subject: [PATCH] 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). --- lib/mtio.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) 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) -- 2.11.0