[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 46/51] tests/qtest: libqtest: Replace the call to close a socket
From: |
Bin Meng |
Subject: |
[PATCH 46/51] tests/qtest: libqtest: Replace the call to close a socket with closesocket() |
Date: |
Wed, 24 Aug 2022 17:40:24 +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>
---
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 99e52ff571..918f4657ed 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -115,7 +115,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;
}
@@ -126,7 +126,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;
}
@@ -512,8 +512,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 35/51] tests/qtest: device-plug-test: Reverse the usage of double/single quotes, (continued)
- [PATCH 37/51] tests/qtest: migration-test: Disable IO redirection for win32, Bin Meng, 2022/08/24
- [PATCH 42/51] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab, Bin Meng, 2022/08/24
- [PATCH 41/51] tests/qtest: migration-test: Kill "to" after migration is canceled, Bin Meng, 2022/08/24
- [PATCH 45/51] tests/qtest: prom-env-test: Use double quotes to pass the prom-env option, Bin Meng, 2022/08/24
- [PATCH 46/51] tests/qtest: libqtest: Replace the call to close a socket with closesocket(),
Bin Meng <=
- [PATCH 36/51] tests/qtest: machine-none-test: Use double quotes to pass the cpu option, Bin Meng, 2022/08/24
- [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32, Bin Meng, 2022/08/24
[PATCH 44/51] tests/qtest: microbit-test: Fix socket access for win32, Bin Meng, 2022/08/24
[PATCH 47/51] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32, Bin Meng, 2022/08/24