aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2010-05-12 18:42:20 +0200
committerAndreas Schneider <mail@cynapses.org>2010-05-12 18:42:20 +0200
commit101a65378c2a658f6d510e5c28b2e2bcfb0906f7 (patch)
tree35b4dfd4f38289dfae20b6bdb7173a4a3eafa0b8
parent739234afb9f9c644afacbb7fd8e8a3a421adf63b (diff)
parent91ef298e7d34f81a31e28025f2a933640ae7f4bf (diff)
downloadlibssh-101a65378c2a658f6d510e5c28b2e2bcfb0906f7.tar.gz
libssh-101a65378c2a658f6d510e5c28b2e2bcfb0906f7.tar.xz
libssh-101a65378c2a658f6d510e5c28b2e2bcfb0906f7.zip
Merge branch 'look'
-rw-r--r--include/libssh/poll.h1
-rw-r--r--libssh/poll.c38
-rw-r--r--libssh/socket.c2
3 files changed, 33 insertions, 8 deletions
diff --git a/include/libssh/poll.h b/include/libssh/poll.h
index 29512450..81891a13 100644
--- a/include/libssh/poll.h
+++ b/include/libssh/poll.h
@@ -76,6 +76,7 @@ typedef struct ssh_pollfd_struct {
typedef unsigned long int nfds_t;
#endif /* HAVE_POLL */
+void ssh_poll_init(void);
int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout);
typedef struct ssh_poll_ctx_struct *ssh_poll_ctx;
typedef struct ssh_poll_handle_struct *ssh_poll_handle;
diff --git a/libssh/poll.c b/libssh/poll.c
index fb88596e..dc28b9b0 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 a8d76050..935baee7 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;
}