[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 30/39] tests/qtest: libqtest: Replace the call to close a sock
From: |
Bin Meng |
Subject: |
[PATCH v2 30/39] tests/qtest: libqtest: Replace the call to close a socket with closesocket() |
Date: |
Tue, 20 Sep 2022 18:31:50 +0800 |
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>
---
(no changes since v1)
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 5d15e39289..08c4e76ffe 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -113,7 +113,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;
}
@@ -124,7 +124,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;
}
@@ -507,8 +507,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.34.1
- Re: [PATCH v2 25/39] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32, (continued)
- [PATCH v2 31/39] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32, Bin Meng, 2022/09/20
- [PATCH v2 33/39] io/channel-watch: Drop the unnecessary cast, Bin Meng, 2022/09/20
- [PATCH v2 36/39] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes, Bin Meng, 2022/09/20
- [PATCH v2 24/39] tests/qtest: virtio-net-failover: Disable migration tests for win32, Bin Meng, 2022/09/20
- [PATCH v2 30/39] tests/qtest: libqtest: Replace the call to close a socket with closesocket(),
Bin Meng <=
- [PATCH v2 32/39] io/channel-watch: Drop a superfluous '#ifdef WIN32', Bin Meng, 2022/09/20
- [PATCH v2 34/39] io/channel-watch: Fix socket watch on Windows, Bin Meng, 2022/09/20
- [PATCH v2 37/39] .gitlab-ci.d/windows.yml: Display meson test logs, Bin Meng, 2022/09/20
- [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32, Bin Meng, 2022/09/20
- Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32, Dr. David Alan Gilbert, 2022/09/21
- Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32, Daniel P . Berrangé, 2022/09/21
- Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32, Bin Meng, 2022/09/21
- Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32, Daniel P . Berrangé, 2022/09/22
- Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32, Bin Meng, 2022/09/22
- Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32, Daniel P . Berrangé, 2022/09/27