iovec-util: make IOVEC_INCREMENT a regular function too

Even more than with the previous commit, this is not a trivial function
and there's no reason to believe this will actually be inlined nor that
it would be beneficial.
This commit is contained in:
Lennart Poettering
2023-10-20 10:43:50 +02:00
parent 9599ea28b4
commit 986235a99a
6 changed files with 30 additions and 26 deletions
+25
View File
@@ -14,6 +14,31 @@ size_t iovec_total_size(const struct iovec *i, size_t n) {
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;
+1 -22
View File
@@ -9,28 +9,7 @@
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) {}
+1 -1
View File
@@ -541,7 +541,7 @@ static int write_to_syslog(
if (!syslog_is_stream)
break;
if (IOVEC_INCREMENT(iovec, ELEMENTSOF(iovec), n))
if (iovec_increment(iovec, ELEMENTSOF(iovec), n))
break;
}