iovec-util: make IOVEC_TOTAL_SIZE() a regular function

The function isn't necessarily fast (it's O(n)), and there's no reason
to have it defined as inline function, since it's neither fast, nor
entirely trivial.
This commit is contained in:
Lennart Poettering
2023-10-20 10:43:50 +02:00
parent bd1ae17833
commit c24e0dbea1
7 changed files with 19 additions and 16 deletions
+10
View File
@@ -3,6 +3,16 @@
#include "iovec-util.h"
#include "string-util.h"
size_t iovec_total_size(const struct iovec *i, size_t n) {
size_t sum = 0;
assert(i || n == 0);
FOREACH_ARRAY(j, i, n)
sum += j->iov_len;
return sum;
}
char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value) {
char *x;
+1 -8
View File
@@ -7,14 +7,7 @@
#include "macro.h"
static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, size_t n) {
size_t r = 0;
for (size_t j = 0; j < n; j++)
r += i[j].iov_len;
return r;
}
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),
+2 -2
View File
@@ -962,7 +962,7 @@ static void server_write_to_journal(
return;
}
log_debug_errno(r, "Failed to write entry to %s (%zu items, %zu bytes): %m", f->path, n, IOVEC_TOTAL_SIZE(iovec, n));
log_debug_errno(r, "Failed to write entry to %s (%zu items, %zu bytes): %m", f->path, n, iovec_total_size(iovec, n));
if (!shall_try_append_again(f, r))
return;
@@ -992,7 +992,7 @@ static void server_write_to_journal(
if (r < 0)
log_ratelimit_error_errno(r, FAILED_TO_WRITE_ENTRY_RATELIMIT,
"Failed to write entry to %s (%zu items, %zu bytes) despite vacuuming, ignoring: %m",
f->path, n, IOVEC_TOTAL_SIZE(iovec, n));
f->path, n, iovec_total_size(iovec, n));
else
server_schedule_sync(s, priority);
}
+2 -2
View File
@@ -1506,7 +1506,7 @@ _public_ int sd_bus_message_append_string_iovec(
assert_return(iov || n == 0, -EINVAL);
assert_return(!m->poisoned, -ESTALE);
size = IOVEC_TOTAL_SIZE(iov, n);
size = iovec_total_size(iov, n);
r = sd_bus_message_append_string_space(m, size, &p);
if (r < 0)
@@ -2160,7 +2160,7 @@ _public_ int sd_bus_message_append_array_iovec(
assert_return(iov || n == 0, -EINVAL);
assert_return(!m->poisoned, -ESTALE);
size = IOVEC_TOTAL_SIZE(iov, n);
size = iovec_total_size(iov, n);
r = sd_bus_message_append_array_space(m, type, size, &p);
if (r < 0)
+1 -1
View File
@@ -585,7 +585,7 @@ static int pid_notify_with_fds_internal(
send_ucred = false;
} else {
/* Unless we're using SOCK_STREAM, we expect to write all the contents immediately. */
if (type != SOCK_STREAM && (size_t) n < IOVEC_TOTAL_SIZE(msghdr.msg_iov, msghdr.msg_iovlen))
if (type != SOCK_STREAM && (size_t) n < iovec_total_size(msghdr.msg_iov, msghdr.msg_iovlen))
return -EIO;
/* Make sure we only send fds and ucred once, even if we're using SOCK_STREAM. */
+1 -1
View File
@@ -171,7 +171,7 @@ ssize_t dnstls_stream_writev(DnsStream *stream, const struct iovec *iov, size_t
assert(stream->encrypted);
assert(stream->dnstls_data.session);
assert(iov);
assert(IOVEC_TOTAL_SIZE(iov, iovcnt) > 0);
assert(iovec_total_size(iov, iovcnt) > 0);
gnutls_record_cork(stream->dnstls_data.session);
+2 -2
View File
@@ -322,14 +322,14 @@ ssize_t dnstls_stream_writev(DnsStream *stream, const struct iovec *iov, size_t
assert(stream->encrypted);
assert(stream->dnstls_data.ssl);
assert(iov);
assert(IOVEC_TOTAL_SIZE(iov, iovcnt) > 0);
assert(iovec_total_size(iov, iovcnt) > 0);
if (iovcnt == 1)
return dnstls_stream_write(stream, iov[0].iov_base, iov[0].iov_len);
/* As of now, OpenSSL can not accumulate multiple writes, so join into a
single buffer. Suboptimal, but better than multiple SSL_write calls. */
count = IOVEC_TOTAL_SIZE(iov, iovcnt);
count = iovec_total_size(iov, iovcnt);
buf = new(char, count);
for (size_t i = 0, pos = 0; i < iovcnt; pos += iov[i].iov_len, i++)
memcpy(buf + pos, iov[i].iov_base, iov[i].iov_len);