1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-12-02 01:17:52 +03:00

Added runtime detection of WSAPoll().

Signed-off-by: Andreas Schneider <mail@cynapses.org>
This commit is contained in:
Andreas Schneider
2010-05-12 15:47:26 +02:00
parent 4ecefb5017
commit 91ef298e7d
3 changed files with 33 additions and 8 deletions

View File

@@ -76,6 +76,7 @@ typedef struct ssh_pollfd_struct {
typedef unsigned long int nfds_t; typedef unsigned long int nfds_t;
#endif /* HAVE_POLL */ #endif /* HAVE_POLL */
void ssh_poll_init(void);
int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout); 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_ctx_struct *ssh_poll_ctx;
typedef struct ssh_poll_handle_struct *ssh_poll_handle; typedef struct ssh_poll_handle_struct *ssh_poll_handle;

View File

@@ -63,6 +63,10 @@ struct ssh_poll_ctx_struct {
#ifdef HAVE_POLL #ifdef HAVE_POLL
#include <poll.h> #include <poll.h>
void ssh_poll_init(void) {
return;
}
int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) { int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) {
return poll((struct pollfd *) fds, nfds, 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 #endif
#include <time.h> #include <time.h>
#include <windows.h>
#include <winsock2.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 #else
#include <sys/select.h> #include <sys/select.h>
#include <sys/socket.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) { static int bsd_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) {
fd_set readfds, writefds, exceptfds; fd_set readfds, writefds, exceptfds;
struct timeval tv, *ptv; struct timeval tv, *ptv;
int max_fd, rc; socket_t max_fd;
int rc;
nfds_t i; nfds_t i;
if (fds == NULL) { if (fds == NULL) {
@@ -189,14 +202,23 @@ static int bsd_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) {
return rc; 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) { int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) {
#if 0 return win_poll(fds, nfds, timeout);
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600) */
return WSAPoll(fds, nfds, timeout);
#endif
#endif
return bsd_poll(fds, nfds, timeout);
} }
#endif /* HAVE_POLL */ #endif /* HAVE_POLL */

View File

@@ -98,6 +98,8 @@ int ssh_socket_init(void) {
if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) { if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) {
return -1; return -1;
} }
ssh_poll_init();
#endif #endif
return 0; return 0;
} }