// read/write helpers static bool write_all(int fd, const void *data, size_t len) { debug("sending(%d)\n%.*s\n", fd, (int)len, (char*)data); const char *buf = (const char *)data; size_t remaining = len; while (remaining > 0) { ssize_t n = write(fd, buf, remaining); if (n < 0) { if (errno == EINTR) continue; return false; } if (n == 0) break; buf += n; remaining -= n; } return (remaining == 0); } static bool write_header_body(int fd, str header, str body){ unless(quieter_logs) debug("write header (fd:%d) [len:%ld] body [len:%ld]\n", fd, header.len, body.len); struct iovec iov[2]; iov[0].iov_base = header.data; iov[0].iov_len = header.len; iov[1].iov_base = body.data; iov[1].iov_len = body.len; // TODO writev() may partially write, we should send remaining partial and rest of buffers (calc by wsz) ssize_t const wsz = writev(fd, iov, 2); if(wsz < 0){ warnsys("write_header_body"); return false; } if(wsz != header.len + body.len) return false; return true; }