aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2023-02-21 16:47:51 +0400
committerMarc-André Lureau <marcandre.lureau@redhat.com>2023-03-13 15:23:37 +0400
commitf5fd677ae7cf7cfb07b12adbfd479c460ddc3ac5 (patch)
tree20c527712fd1611992b572d4362a41011392349c /util
parent3ffef1a55ca3b55fa64d43cd35af5adb2c260463 (diff)
downloadqemu-f5fd677ae7cf7cfb07b12adbfd479c460ddc3ac5.zip
qemu-f5fd677ae7cf7cfb07b12adbfd479c460ddc3ac5.tar.gz
qemu-f5fd677ae7cf7cfb07b12adbfd479c460ddc3ac5.tar.bz2
win32/socket: introduce qemu_socket_select() helper
This is a wrapper for WSAEventSelect, with Error handling. By default, it will produce a warning, so callers don't have to be modified now, and yet we can spot potential mis-use. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Message-Id: <20230221124802.4103554-7-marcandre.lureau@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/aio-win32.c2
-rw-r--r--util/main-loop.c6
-rw-r--r--util/oslib-win32.c17
3 files changed, 20 insertions, 5 deletions
diff --git a/util/aio-win32.c b/util/aio-win32.c
index 80cfe01..be5136e 100644
--- a/util/aio-win32.c
+++ b/util/aio-win32.c
@@ -115,7 +115,7 @@ void aio_set_fd_handler(AioContext *ctx,
QLIST_INSERT_HEAD_RCU(&ctx->aio_handlers, node, node);
event = event_notifier_get_handle(&ctx->notifier);
- WSAEventSelect(node->pfd.fd, event, bitmask);
+ qemu_socket_select(node->pfd.fd, event, bitmask, NULL);
}
if (old_node) {
aio_remove_fd_handler(ctx, old_node);
diff --git a/util/main-loop.c b/util/main-loop.c
index 3c0f525..16e837f 100644
--- a/util/main-loop.c
+++ b/util/main-loop.c
@@ -416,9 +416,9 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
void qemu_fd_register(int fd)
{
- WSAEventSelect(fd, event_notifier_get_handle(&qemu_aio_context->notifier),
- FD_READ | FD_ACCEPT | FD_CLOSE |
- FD_CONNECT | FD_WRITE | FD_OOB);
+ qemu_socket_select(fd, event_notifier_get_handle(&qemu_aio_context->notifier),
+ FD_READ | FD_ACCEPT | FD_CLOSE |
+ FD_CONNECT | FD_WRITE | FD_OOB, NULL);
}
static int pollfds_fill(GArray *pollfds, fd_set *rfds, fd_set *wfds,
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 528c9ee..df752fc 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -180,7 +180,7 @@ static int socket_error(void)
void qemu_socket_set_block(int fd)
{
unsigned long opt = 0;
- WSAEventSelect(fd, NULL, 0);
+ qemu_socket_select(fd, NULL, 0, NULL);
ioctlsocket(fd, FIONBIO, &opt);
}
@@ -283,6 +283,21 @@ char *qemu_get_pid_name(pid_t pid)
}
+bool qemu_socket_select(SOCKET s, WSAEVENT hEventObject,
+ long lNetworkEvents, Error **errp)
+{
+ if (errp == NULL) {
+ errp = &error_warn;
+ }
+
+ if (WSAEventSelect(s, hEventObject, lNetworkEvents) != 0) {
+ error_setg_win32(errp, WSAGetLastError(), "failed to WSAEventSelect()");
+ return false;
+ }
+
+ return true;
+}
+
#undef connect
int qemu_connect_wrap(int sockfd, const struct sockaddr *addr,
socklen_t addrlen)