mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-02 01:17:52 +03:00
poll: Fixed the usage of WSAPoll() on Windows.
This should fix ticket #101.
This commit is contained in:
@@ -94,10 +94,10 @@ int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) {
|
|||||||
|
|
||||||
#else /* HAVE_POLL */
|
#else /* HAVE_POLL */
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
typedef int (*poll_fn)(ssh_pollfd_t *, nfds_t, int);
|
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
|
#ifdef _WIN32
|
||||||
#ifndef STRICT
|
#ifndef STRICT
|
||||||
@@ -108,6 +108,25 @@ static poll_fn win_poll;
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winsock2.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"
|
#define WS2_LIBRARY "ws2_32.dll"
|
||||||
static HINSTANCE hlib;
|
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) {
|
void ssh_poll_init(void) {
|
||||||
poll_fn wsa_poll = NULL;
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
hlib = LoadLibrary(WS2_LIBRARY);
|
hlib = LoadLibrary(WS2_LIBRARY);
|
||||||
if (hlib != NULL) {
|
if (hlib != NULL) {
|
||||||
wsa_poll = (poll_fn) GetProcAddress(hlib, "WSAPoll");
|
wsa_poll = (WSAPoll_FunctionType) (void *) GetProcAddress(hlib, "WSAPoll");
|
||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
if (wsa_poll == NULL) {
|
if (wsa_poll == NULL) {
|
||||||
win_poll = bsd_poll;
|
ssh_poll_emu = bsd_poll;
|
||||||
} else {
|
} else {
|
||||||
win_poll = wsa_poll;
|
ssh_poll_emu = win_poll;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssh_poll_cleanup(void) {
|
void ssh_poll_cleanup(void) {
|
||||||
win_poll = bsd_poll;
|
ssh_poll_emu = bsd_poll;
|
||||||
|
wsa_poll = NULL;
|
||||||
|
|
||||||
FreeLibrary(hlib);
|
FreeLibrary(hlib);
|
||||||
|
|
||||||
@@ -268,7 +286,7 @@ void ssh_poll_cleanup(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) {
|
||||||
return win_poll(fds, nfds, timeout);
|
return (ssh_poll_emu)(fds, nfds, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* HAVE_POLL */
|
#endif /* HAVE_POLL */
|
||||||
|
|||||||
Reference in New Issue
Block a user