return r;
}
-static inline size_t IOVEC_INCREMENT(struct iovec *i, size_t n, size_t k) {
- size_t j;
+static inline bool IOVEC_INCREMENT(struct iovec *i, size_t n, size_t k) {
+ /* Returns true if there is nothing else to send (bytes written cover all of the iovec),
+ * false if there's still work to do. */
- for (j = 0; j < n; j++) {
+ for (size_t j = 0; j < n; j++) {
size_t sub;
- if (_unlikely_(k <= 0))
- break;
+ if (i[j].iov_len == 0)
+ continue;
+ if (k == 0)
+ return false;
sub = MIN(i[j].iov_len, k);
i[j].iov_len -= sub;
k -= sub;
}
- return k;
+ assert(k == 0); /* Anything else would mean that we wrote more bytes than available,
+ * or the kernel reported writing more bytes than sent. */
+ return true;
}
static inline bool FILE_SIZE_VALID(uint64_t l) {
if (n < 0)
return -errno;
- if (!syslog_is_stream ||
- (size_t) n >= IOVEC_TOTAL_SIZE(iovec, ELEMENTSOF(iovec)))
+ if (!syslog_is_stream)
break;
- IOVEC_INCREMENT(iovec, ELEMENTSOF(iovec), n);
+ if (IOVEC_INCREMENT(iovec, ELEMENTSOF(iovec), n))
+ break;
}
return 1;