diff options
-rw-r--r-- | include/sysemu/os-win32.h | 5 | ||||
-rw-r--r-- | io/channel-socket.c | 4 | ||||
-rw-r--r-- | io/channel-watch.c | 6 | ||||
-rw-r--r-- | util/aio-win32.c | 2 | ||||
-rw-r--r-- | util/main-loop.c | 6 | ||||
-rw-r--r-- | util/oslib-win32.c | 17 |
6 files changed, 30 insertions, 10 deletions
diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index 97d0243..9f842ae 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -29,6 +29,7 @@ #include <winsock2.h> #include <windows.h> #include <ws2tcpip.h> +#include "qemu/typedefs.h" #ifdef HAVE_AFUNIX_H #include <afunix.h> @@ -164,6 +165,10 @@ static inline void qemu_funlockfile(FILE *f) #endif } +/* Helper for WSAEventSelect, to report errors */ +bool qemu_socket_select(SOCKET s, WSAEVENT hEventObject, + long lNetworkEvents, Error **errp); + /* We wrap all the sockets functions so that we can * set errno based on WSAGetLastError() */ diff --git a/io/channel-socket.c b/io/channel-socket.c index 2040297..0bc29c4 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -442,7 +442,7 @@ static void qio_channel_socket_finalize(Object *obj) } } #ifdef WIN32 - WSAEventSelect(ioc->fd, NULL, 0); + qemu_socket_select(ioc->fd, NULL, 0, NULL); #endif closesocket(ioc->fd); ioc->fd = -1; @@ -846,7 +846,7 @@ qio_channel_socket_close(QIOChannel *ioc, if (sioc->fd != -1) { #ifdef WIN32 - WSAEventSelect(sioc->fd, NULL, 0); + qemu_socket_select(sioc->fd, NULL, 0, NULL); #endif if (qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_LISTEN)) { socket_listen_cleanup(sioc->fd, errp); diff --git a/io/channel-watch.c b/io/channel-watch.c index ad7c568..6ac4100 100644 --- a/io/channel-watch.c +++ b/io/channel-watch.c @@ -281,9 +281,9 @@ GSource *qio_channel_create_socket_watch(QIOChannel *ioc, GSource *source; QIOChannelSocketSource *ssource; - WSAEventSelect(socket, ioc->event, - FD_READ | FD_ACCEPT | FD_CLOSE | - FD_CONNECT | FD_WRITE | FD_OOB); + qemu_socket_select(socket, ioc->event, + FD_READ | FD_ACCEPT | FD_CLOSE | + FD_CONNECT | FD_WRITE | FD_OOB, NULL); source = g_source_new(&qio_channel_socket_source_funcs, sizeof(QIOChannelSocketSource)); 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) |