[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 28/37] tests/qtest: libqtest: Replace the call to close a socket w
From: |
Thomas Huth |
Subject: |
[PULL 28/37] tests/qtest: libqtest: Replace the call to close a socket with closesocket() |
Date: |
Wed, 28 Sep 2022 09:18:34 +0200 |
From: Bin Meng <bin.meng@windriver.com>
close() is a *nix function. It works on any file descriptor, and
sockets in *nix are an example of a file descriptor.
closesocket() is a Windows-specific function, which works only
specifically with sockets. Sockets on Windows do not use *nix-style
file descriptors, and socket() returns a handle to a kernel object
instead, so it must be closed with closesocket().
In QEMU there is already a logic to handle such platform difference
in os-posix.h and os-win32.h, that:
* closesocket maps to close on POSIX
* closesocket maps to a wrapper that calls the real closesocket()
on Windows
Replace the call to close a socket with closesocket() instead.
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20220925113032.1949844-46-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/qtest/libqtest.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 5c4a509c58..4f4b2d6477 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -97,7 +97,7 @@ static int socket_accept(int sock)
(void *)&timeout, sizeof(timeout))) {
fprintf(stderr, "%s failed to set SO_RCVTIMEO: %s\n",
__func__, strerror(errno));
- close(sock);
+ closesocket(sock);
return -1;
}
@@ -108,7 +108,7 @@ static int socket_accept(int sock)
if (ret == -1) {
fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno));
}
- close(sock);
+ closesocket(sock);
return ret;
}
@@ -421,8 +421,8 @@ void qtest_quit(QTestState *s)
qtest_remove_abrt_handler(s);
qtest_kill_qemu(s);
- close(s->fd);
- close(s->qmp_fd);
+ closesocket(s->fd);
+ closesocket(s->qmp_fd);
g_string_free(s->rx, true);
for (GList *it = s->pending_events; it != NULL; it = it->next) {
--
2.31.1
- [PULL 15/37] tests/unit: test-qga: Avoid using hardcoded /tmp, (continued)
- [PULL 15/37] tests/unit: test-qga: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 13/37] tests/qtest: libqtest: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 05/37] tests/qtest: cxl-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 10/37] tests/qtest: vhost-user-blk-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 21/37] tests/qtest: libqtest: Exclude the *_fds APIs for win32, Thomas Huth, 2022/09/28
- [PULL 22/37] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32, Thomas Huth, 2022/09/28
- [PULL 11/37] tests/qtest: virtio-blk-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 20/37] tests/qtest: libqtest: Adapt global_qtest declaration for win32, Thomas Huth, 2022/09/28
- [PULL 24/37] tests/qtest: migration-test: Disable IO redirection for win32, Thomas Huth, 2022/09/28
- [PULL 27/37] tests/qtest: microbit-test: Fix socket access for win32, Thomas Huth, 2022/09/28
- [PULL 28/37] tests/qtest: libqtest: Replace the call to close a socket with closesocket(),
Thomas Huth <=
- [PULL 30/37] .gitlab-ci.d/windows.yml: Display meson test logs, Thomas Huth, 2022/09/28
- [PULL 32/37] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 34/37] tests/qtest: qmp-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 33/37] tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 35/37] tests/qtest: vhost-user-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 36/37] tests/qtest: boot-serial-test: Close the serial file before starting QEMU, Thomas Huth, 2022/09/28
- [PULL 09/37] tests/qtest: ide-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 12/37] tests/qtest: virtio-scsi-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 16/37] tests: vhost-user-bridge: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 17/37] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32, Thomas Huth, 2022/09/28