diff options
| author | Michal Luczaj <mhal@rbox.co> | 2025-05-22 01:18:23 +0200 |
|---|---|---|
| committer | Paolo Abeni <pabeni@redhat.com> | 2025-05-27 11:05:21 +0200 |
| commit | e78e0596c762609ee5a92bd9d38351694b52f249 (patch) | |
| tree | a64765bef42f3a2c1bee01b8a74375bbba34086e /tools/testing/vsock/util.c | |
| parent | vsock: Move lingering logic to af_vsock core (diff) | |
| download | linux-e78e0596c762609ee5a92bd9d38351694b52f249.tar.gz linux-e78e0596c762609ee5a92bd9d38351694b52f249.zip | |
vsock/test: Introduce vsock_wait_sent() helper
Distill the virtio_vsock_sock::bytes_unsent checking loop (ioctl SIOCOUTQ)
and move it to utils. Tweak the comment.
Signed-off-by: Michal Luczaj <mhal@rbox.co>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://patch.msgid.link/20250522-vsock-linger-v6-3-2ad00b0e447e@rbox.co
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Diffstat (limited to 'tools/testing/vsock/util.c')
| -rw-r--r-- | tools/testing/vsock/util.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index de25892f865f..4427d459e199 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -17,6 +17,7 @@ #include <assert.h> #include <sys/epoll.h> #include <sys/mman.h> +#include <linux/sockios.h> #include "timeout.h" #include "control.h" @@ -96,6 +97,30 @@ void vsock_wait_remote_close(int fd) close(epollfd); } +/* Wait until transport reports no data left to be sent. + * Return false if transport does not implement the unsent_bytes() callback. + */ +bool vsock_wait_sent(int fd) +{ + int ret, sock_bytes_unsent; + + timeout_begin(TIMEOUT); + do { + ret = ioctl(fd, SIOCOUTQ, &sock_bytes_unsent); + if (ret < 0) { + if (errno == EOPNOTSUPP) + break; + + perror("ioctl(SIOCOUTQ)"); + exit(EXIT_FAILURE); + } + timeout_check("SIOCOUTQ"); + } while (sock_bytes_unsent != 0); + timeout_end(); + + return !ret; +} + /* Create socket <type>, bind to <cid, port> and return the file descriptor. */ int vsock_bind(unsigned int cid, unsigned int port, int type) { |
