diff options
author | Andreas Schneider <asn@cynapses.org> | 2010-08-11 12:21:30 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cynapses.org> | 2010-08-25 23:12:27 +0200 |
commit | 5b9d92c36fbdab7aedc02cb17cfabce3e705ca9e (patch) | |
tree | 51ce6b23386ffc78aa2617fb232c39ed4400dba2 | |
parent | edc6b2cef276d62034a6dd3f8ef5338e1a467045 (diff) | |
download | libssh-5b9d92c36fbdab7aedc02cb17cfabce3e705ca9e.tar.gz libssh-5b9d92c36fbdab7aedc02cb17cfabce3e705ca9e.tar.xz libssh-5b9d92c36fbdab7aedc02cb17cfabce3e705ca9e.zip |
poll: Fixed the usage of WSAPoll() on Windows.
This should fix ticket #101.
-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 b6b4a430..ab18be72 100644 --- a/libssh/poll.c +++ b/libssh/poll.c @@ -73,10 +73,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 @@ -87,6 +87,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; @@ -222,24 +241,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); @@ -247,7 +265,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 */ |