Skip to content

Commit 8b07b7e

Browse files
mmhalPaolo Abeni
authored andcommitted
vsock/test: Introduce enable_so_linger() helper
Add a helper function that sets SO_LINGER. Adapt the caller. Signed-off-by: Michal Luczaj <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent e78e059 commit 8b07b7e

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

tools/testing/vsock/util.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,16 @@ void enable_so_zerocopy_check(int fd)
823823
setsockopt_int_check(fd, SOL_SOCKET, SO_ZEROCOPY, 1,
824824
"setsockopt SO_ZEROCOPY");
825825
}
826+
827+
void enable_so_linger(int fd, int timeout)
828+
{
829+
struct linger optval = {
830+
.l_onoff = 1,
831+
.l_linger = timeout
832+
};
833+
834+
if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &optval, sizeof(optval))) {
835+
perror("setsockopt(SO_LINGER)");
836+
exit(EXIT_FAILURE);
837+
}
838+
}

tools/testing/vsock/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ void setsockopt_int_check(int fd, int level, int optname, int val,
8080
void setsockopt_timeval_check(int fd, int level, int optname,
8181
struct timeval val, char const *errmsg);
8282
void enable_so_zerocopy_check(int fd);
83+
void enable_so_linger(int fd, int timeout);
8384
#endif /* UTIL_H */

tools/testing/vsock/vsock_test.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,10 +1813,6 @@ static void test_stream_connect_retry_server(const struct test_opts *opts)
18131813

18141814
static void test_stream_linger_client(const struct test_opts *opts)
18151815
{
1816-
struct linger optval = {
1817-
.l_onoff = 1,
1818-
.l_linger = 1
1819-
};
18201816
int fd;
18211817

18221818
fd = vsock_stream_connect(opts->peer_cid, opts->peer_port);
@@ -1825,11 +1821,7 @@ static void test_stream_linger_client(const struct test_opts *opts)
18251821
exit(EXIT_FAILURE);
18261822
}
18271823

1828-
if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &optval, sizeof(optval))) {
1829-
perror("setsockopt(SO_LINGER)");
1830-
exit(EXIT_FAILURE);
1831-
}
1832-
1824+
enable_so_linger(fd, 1);
18331825
close(fd);
18341826
}
18351827

0 commit comments

Comments
 (0)