diff options
author | Andreas Schneider <mail@cynapses.org> | 2010-05-12 15:47:26 +0200 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2010-05-12 18:22:09 +0200 |
commit | 91ef298e7d34f81a31e28025f2a933640ae7f4bf (patch) | |
tree | ab02b5563492c210c3cb43fe0cc2bf974656da85 /libssh | |
parent | 4ecefb501702cb993eb3acd98876a378783526b6 (diff) | |
download | libssh-91ef298e7d34f81a31e28025f2a933640ae7f4bf.tar.gz libssh-91ef298e7d34f81a31e28025f2a933640ae7f4bf.tar.xz libssh-91ef298e7d34f81a31e28025f2a933640ae7f4bf.zip |
Added runtime detection of WSAPoll().
Signed-off-by: Andreas Schneider <mail@cynapses.org>
Diffstat (limited to 'libssh')
-rw-r--r-- | libssh/poll.c | 38 | ||||
-rw-r--r-- | libssh/socket.c | 2 |
2 files changed, 32 insertions, 8 deletions
diff --git a/libssh/poll.c b/libssh/poll.c index fb88596..dc28b9b 100644 --- a/libssh/poll.c +++ b/libssh/poll.c @@ -63,6 +63,10 @@ struct ssh_poll_ctx_struct { #ifdef HAVE_POLL #include <poll.h> +void ssh_poll_init(void) { + return; +} + int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) { return poll((struct pollfd *) fds, nfds, timeout); } @@ -77,7 +81,15 @@ int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) { #endif #include <time.h> +#include <windows.h> #include <winsock2.h> + +#define WS2_LIBRARY "ws2_32.dll" +typedef int (*poll_fn)(ssh_pollfd_t *, nfds_t, int); + +static poll_fn win_poll; +static HINSTANCE hlib; + #else #include <sys/select.h> #include <sys/socket.h> @@ -88,7 +100,8 @@ int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) { static int bsd_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) { fd_set readfds, writefds, exceptfds; struct timeval tv, *ptv; - int max_fd, rc; + socket_t max_fd; + int rc; nfds_t i; if (fds == NULL) { @@ -189,14 +202,23 @@ static int bsd_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) { return rc; } -/* TODO Detect if WSAPoll() is available and load it dynamically */ +void ssh_poll_init(void) { + poll_fn wsa_poll = NULL; + + hlib = LoadLibrary(WS2_LIBRARY); + if (hlib != NULL) { + wsa_poll = (poll_fn) GetProcAddress(hlib, "WSAPoll"); + } + + if (wsa_poll == NULL) { + win_poll = bsd_poll; + } else { + win_poll = wsa_poll; + } +} + int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) { -#if 0 -#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600) */ - return WSAPoll(fds, nfds, timeout); -#endif -#endif - return bsd_poll(fds, nfds, timeout); + return win_poll(fds, nfds, timeout); } #endif /* HAVE_POLL */ diff --git a/libssh/socket.c b/libssh/socket.c index a8d7605..935baee 100644 --- a/libssh/socket.c +++ b/libssh/socket.c @@ -98,6 +98,8 @@ int ssh_socket_init(void) { if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) { return -1; } + + ssh_poll_init(); #endif return 0; } |