iovec-util: rename iovec_increment() -> iovec_inc_many()
Also, - use iovec_inc() in the loop, - do not return true when input is NULL or all iovec are empty.
This commit is contained in:
@@ -30,29 +30,30 @@ size_t iovec_total_size(const struct iovec *iovec, size_t n) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
bool iovec_increment(struct iovec *iovec, size_t n, size_t k) {
|
||||
bool iovec_inc_many(struct iovec *iovec, size_t n, size_t k) {
|
||||
assert(iovec || 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. */
|
||||
|
||||
bool have = false;
|
||||
FOREACH_ARRAY(j, iovec, 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;
|
||||
size_t sub = MIN(j->iov_len, k);
|
||||
iovec_inc(j, sub);
|
||||
k -= sub;
|
||||
|
||||
have = have || iovec_is_set(j);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return !have;
|
||||
}
|
||||
|
||||
struct iovec* iovec_make_string(struct iovec *iovec, const char *s) {
|
||||
|
||||
@@ -11,7 +11,7 @@ extern const struct iovec iovec_empty; /* Points to an empty, but valid (i.e.
|
||||
|
||||
size_t iovec_total_size(const struct iovec *iovec, size_t n) _nonnull_if_nonzero_(1, 2);
|
||||
|
||||
bool iovec_increment(struct iovec *iovec, size_t n, size_t k) _nonnull_if_nonzero_(1, 2);
|
||||
bool iovec_inc_many(struct iovec *iovec, size_t n, size_t k) _nonnull_if_nonzero_(1, 2);
|
||||
|
||||
struct iovec* iovec_make_string(struct iovec *iovec, const char *s);
|
||||
|
||||
|
||||
+1
-1
@@ -557,7 +557,7 @@ static int write_to_syslog(
|
||||
if (!syslog_is_stream)
|
||||
break;
|
||||
|
||||
if (iovec_increment(iovec, ELEMENTSOF(iovec), n))
|
||||
if (iovec_inc_many(iovec, ELEMENTSOF(iovec), n))
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user