diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2023-02-21 16:47:51 +0400 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2023-03-13 15:23:37 +0400 |
commit | f5fd677ae7cf7cfb07b12adbfd479c460ddc3ac5 (patch) | |
tree | 20c527712fd1611992b572d4362a41011392349c /util/oslib-win32.c | |
parent | 3ffef1a55ca3b55fa64d43cd35af5adb2c260463 (diff) |
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/oslib-win32.c')
-rw-r--r-- | util/oslib-win32.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 528c9ee156..df752fc762 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) |