aboutsummaryrefslogtreecommitdiff
path: root/libssh
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cynapses.org>2010-08-11 12:21:30 +0200
committerAndreas Schneider <asn@cynapses.org>2010-08-25 23:11:54 +0200
commitd99160649363da544537638e28672f90352d86a6 (patch)
tree107952961adbb7a31fcb02a5cbc74a268d5ef920 /libssh
parent14048354d5fe098ae470bc329acba10fad5bc5b6 (diff)
downloadlibssh-d99160649363da544537638e28672f90352d86a6.tar.gz
libssh-d99160649363da544537638e28672f90352d86a6.tar.xz
libssh-d99160649363da544537638e28672f90352d86a6.zip
poll: Fixed the usage of WSAPoll() on Windows.
This should fix ticket #101.
Diffstat (limited to 'libssh')
-rw-r--r--libssh/poll.c38
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 */