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;
}
+1 -1
View File
@@ -41,7 +41,7 @@ static int io_callback(sd_event_source *s, int fd, uint32_t revents, void *userd
else
assert_se(errno == EAGAIN);
} else
IOVEC_INCREMENT(iov, 1, n);
iovec_increment(iov, 1, n);
}
if (revents & EPOLLIN) {
+1 -1
View File
@@ -592,7 +592,7 @@ static int pid_notify_with_fds_internal(
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;
}
+1 -1
View File
@@ -331,7 +331,7 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use
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) {