tcp_l2_buf_flush() open codes the "primary" send of message to the passt tap interface, but calls tcp_l2_buf_flush_part() to handle the case of a short send. Combine these two passt-specific operations into tcp_l2_buf_flush_passt() which is a little cleaner and will enable furrther cleanups. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- tcp.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tcp.c b/tcp.c index ed65a9e..6a59c85 100644 --- a/tcp.c +++ b/tcp.c @@ -1415,19 +1415,25 @@ static int tcp_l2_buf_write_one(struct ctx *c, const struct iovec *iov) } /** - * tcp_l2_buf_flush_part() - Ensure a complete last message on partial sendmsg() + * tcp_l2_buf_flush_passt() - Send a message on the passt tap interface * @c: Execution context * @mh: Message header that was partially sent by sendmsg() - * @sent: Bytes already sent + * @buf_bytes: Total number of bytes to send */ -static void tcp_l2_buf_flush_part(const struct ctx *c, - const struct msghdr *mh, size_t sent) +static void tcp_l2_buf_flush_passt(const struct ctx *c, + const struct msghdr *mh, size_t buf_bytes) { - size_t end = 0, missing; + size_t end = 0, missing, sent; struct iovec *iov; unsigned int i; + ssize_t n; char *p; + n = sendmsg(c->fd_tap, mh, MSG_NOSIGNAL | MSG_DONTWAIT); + if (n < 0 || ((sent = (size_t)n) == buf_bytes)) + return; + + /* Ensure a complete last message on partial sendmsg() */ for (i = 0, iov = mh->msg_iov; i < mh->msg_iovlen; i++, iov++) { end += iov->iov_len; if (end >= sent) @@ -1454,9 +1460,7 @@ static void tcp_l2_buf_flush(struct ctx *c, struct msghdr *mh, return; if (c->mode == MODE_PASST) { - size_t n = sendmsg(c->fd_tap, mh, MSG_NOSIGNAL | MSG_DONTWAIT); - if (n > 0 && n < *buf_bytes) - tcp_l2_buf_flush_part(c, mh, n); + tcp_l2_buf_flush_passt(c, mh, *buf_bytes); } else { size_t i; -- 2.39.0