diff options
-rw-r--r-- | libssh/poll.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/libssh/poll.c b/libssh/poll.c index 34361a9f..a843657b 100644 --- a/libssh/poll.c +++ b/libssh/poll.c @@ -94,10 +94,10 @@ int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) { #else /* HAVE_POLL */ -#include <sys/types.h> - typedef int (*poll_fn)(ssh_pollfd_t *, nfds_t, int); -static poll_fn win_poll; +static poll_fn ssh_poll_emu; + +#include <sys/types.h> #ifdef _WIN32 #ifndef STRICT @@ -108,6 +108,25 @@ static poll_fn win_poll; #include <windows.h> #include <winsock2.h> +#ifndef WSAPOLLFD +typedef ssh_pollfd_t WSAPOLLFD; +#endif + +typedef int (WSAAPI* WSAPoll_FunctionType)(WSAPOLLFD fdarray[], + ULONG nfds, + INT timeout +); + +static WSAPoll_FunctionType wsa_poll; + +int win_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) { + if (wsa_poll) { + return (wsa_poll)(fds, nfds, timeout); + } + + return SOCKET_ERROR; +} + #define WS2_LIBRARY "ws2_32.dll" static HINSTANCE hlib; @@ -243,24 +262,23 @@ static int bsd_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) { } void ssh_poll_init(void) { - poll_fn wsa_poll = NULL; - #ifdef _WIN32 hlib = LoadLibrary(WS2_LIBRARY); if (hlib != NULL) { - wsa_poll = (poll_fn) GetProcAddress(hlib, "WSAPoll"); + wsa_poll = (WSAPoll_FunctionType) (void *) GetProcAddress(hlib, "WSAPoll"); } #endif /* _WIN32 */ if (wsa_poll == NULL) { - win_poll = bsd_poll; + ssh_poll_emu = bsd_poll; } else { - win_poll = wsa_poll; + ssh_poll_emu = win_poll; } } void ssh_poll_cleanup(void) { - win_poll = bsd_poll; + ssh_poll_emu = bsd_poll; + wsa_poll = NULL; FreeLibrary(hlib); @@ -268,7 +286,7 @@ void ssh_poll_cleanup(void) { } int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) { - return win_poll(fds, nfds, timeout); + return (ssh_poll_emu)(fds, nfds, timeout); } #endif /* HAVE_POLL */ |