return sum;
}
+bool iovec_increment(struct iovec *i, size_t n, size_t k) {
+ assert(i || n == 0);
+
+ /* Returns true if there is nothing else to send (bytes written cover all of the iovec),
+ * false if there's still work to do. */
+
+ FOREACH_ARRAY(j, i, n) {
+ size_t sub;
+
+ if (j->iov_len == 0)
+ continue;
+ if (k == 0)
+ return false;
+
+ sub = MIN(j->iov_len, k);
+ j->iov_len -= sub;
+ j->iov_base = (uint8_t*) j->iov_base + sub;
+ k -= sub;
+ }
+
+ 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;
+}
+
char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value) {
char *x;
size_t iovec_total_size(const struct iovec *i, size_t n);
-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 (size_t j = 0; j < n; j++) {
- size_t sub;
-
- if (i[j].iov_len == 0)
- continue;
- if (k == 0)
- return false;
-
- sub = MIN(i[j].iov_len, k);
- i[j].iov_len -= sub;
- i[j].iov_base = (uint8_t*) i[j].iov_base + sub;
- k -= sub;
- }
-
- 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;
-}
+bool iovec_increment(struct iovec *i, size_t n, size_t k);
#define IOVEC_NULL (const struct iovec) {}
if (!syslog_is_stream)
break;
- if (IOVEC_INCREMENT(iovec, ELEMENTSOF(iovec), n))
+ if (iovec_increment(iovec, ELEMENTSOF(iovec), n))
break;
}
else
assert_se(errno == EAGAIN);
} else
- IOVEC_INCREMENT(iov, 1, n);
+ iovec_increment(iov, 1, n);
}
if (revents & EPOLLIN) {
msghdr.msg_control = NULL;
msghdr.msg_controllen = 0;
}
- } while (!IOVEC_INCREMENT(msghdr.msg_iov, msghdr.msg_iovlen, n));
+ } while (!iovec_increment(msghdr.msg_iov, msghdr.msg_iovlen, n));
return 1;
}
IOVEC_MAKE(DNS_PACKET_DATA(s->write_packet), s->write_packet->size),
};
- IOVEC_INCREMENT(iov, ELEMENTSOF(iov), s->n_written);
+ iovec_increment(iov, ELEMENTSOF(iov), s->n_written);
ssize_t ss = dns_stream_writev(s, iov, ELEMENTSOF(iov), 0);
if (ss < 0) {