From 8df031d336d4a7e71c55b34e33a0b7aefdbdb0c0 Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Sat, 29 Mar 2014 07:15:40 +0100 Subject: [PATCH] Remove emulated_poll on Windows --- CMakeLists.txt | 7 +- lib/libwebsockets.c | 8 --- test-server/test-server.c | 9 +-- win32port/win32helpers/websock-w32.c | 103 --------------------------- win32port/win32helpers/websock-w32.h | 6 -- 5 files changed, 2 insertions(+), 131 deletions(-) delete mode 100644 win32port/win32helpers/websock-w32.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 684e5c8d..fec4cd58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,11 +300,6 @@ if (WIN32) list(APPEND HDR_PUBLIC ${WIN32_HELPERS_PATH}/websock-w32.h ) - if (NOT MINGW) - list(APPEND SOURCES - ${WIN32_HELPERS_PATH}/websock-w32.c - ) - endif() include_directories(${WIN32_HELPERS_PATH}) else(WIN32) # Unix. @@ -566,7 +561,7 @@ if (NOT LWS_WITHOUT_TESTAPPS) if (NOT LWS_WITHOUT_TEST_SERVER_EXTPOLL) create_test_app(test-server-extpoll "test-server/test-server.c" - "win32port/win32helpers/websock-w32.c" + "" "${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h") # Set defines for this executable only. set_property( diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 54c0c5fb..b4f7f334 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -47,14 +47,6 @@ int openssl_websocket_private_data_index; #endif -#ifdef __MINGW32__ -#include "../win32port/win32helpers/websock-w32.c" -#else -#ifdef __MINGW64__ -#include "../win32port/win32helpers/websock-w32.c" -#endif -#endif - #ifndef LWS_BUILD_HASH #define LWS_BUILD_HASH "unknown-build-hash" #endif diff --git a/test-server/test-server.c b/test-server/test-server.c index 4259f9d3..481dff6f 100644 --- a/test-server/test-server.c +++ b/test-server/test-server.c @@ -34,14 +34,7 @@ #ifdef WIN32 #ifdef EXTERNAL_POLL - #ifndef WIN32_LEAN_AND_MEAN - #define WIN32_LEAN_AND_MEAN - #endif - #include - #include - #include - - #include "websock-w32.h" +#define poll WSAPoll #endif #else // NOT WIN32 diff --git a/win32port/win32helpers/websock-w32.c b/win32port/win32helpers/websock-w32.c deleted file mode 100644 index a919c4b0..00000000 --- a/win32port/win32helpers/websock-w32.c +++ /dev/null @@ -1,103 +0,0 @@ -#define FD_SETSIZE 256 - -#ifdef __MINGW32__ -#include -#else -#ifdef __MINGW64__ -#include -#else -#include -#endif -#endif - -#include -#include "websock-w32.h" - -PFNWSAPOLL poll = NULL; - -INT WSAAPI emulated_poll(LPWSAPOLLFD fdarray, ULONG nfds, INT timeout) -{ - fd_set readfds; - fd_set writefds; - struct timeval tv; - struct timeval *ptv = &tv; - SOCKET max_socket = 0; - ULONG n = 0; - int waiting; - int pending = 0; - WSAPOLLFD * poll_fd = fdarray; - - if (NULL == fdarray) { - WSASetLastError(WSAEFAULT); - return -1; - } - - FD_ZERO(&readfds); - FD_ZERO(&writefds); - - tv.tv_sec = timeout / 1000; - tv.tv_usec = (timeout % 1000) * 1000; - - if (timeout < 0) - ptv = NULL; - - while (n < nfds) { - - poll_fd->revents = 0; - - if ((int)poll_fd->fd < 0 || !poll_fd->events) - goto skip1; - - if (max_socket < poll_fd->fd) - max_socket = poll_fd->fd; - - if (poll_fd->events & POLLIN) - FD_SET(poll_fd->fd, &readfds); - - if (poll_fd->events & POLLOUT) - FD_SET(poll_fd->fd, &writefds); -skip1: - poll_fd++; - n++; - } - - waiting = select((int)max_socket + 1, &readfds, &writefds, NULL, ptv); - - if (waiting <= 0) - return waiting; - - poll_fd = fdarray; - - while (waiting && nfds--) { - - if (!poll_fd->events) - goto skip2; - - if (poll_fd->fd <= 0) { - poll_fd->revents = POLLNVAL; - goto skip2; - } - - if (FD_ISSET(poll_fd->fd, &readfds)) { - - /* defer POLLHUP / error detect to false read attempt */ - - poll_fd->revents |= POLLIN; - waiting--; - } - - if (FD_ISSET(poll_fd->fd, &writefds)) { - - poll_fd->revents |= poll_fd->events & POLLOUT; - waiting--; - } - - if (poll_fd->revents) - pending++; - -skip2: - poll_fd++; - } - - return pending; -} diff --git a/win32port/win32helpers/websock-w32.h b/win32port/win32helpers/websock-w32.h index 9ce1cae6..4ee964ff 100644 --- a/win32port/win32helpers/websock-w32.h +++ b/win32port/win32helpers/websock-w32.h @@ -46,12 +46,6 @@ typedef struct pollfd { #endif -typedef INT (WSAAPI *PFNWSAPOLL)(LPWSAPOLLFD fdarray, ULONG nfds, INT timeout); -extern PFNWSAPOLL poll; - -#ifndef __MINGW32__ -extern INT WSAAPI emulated_poll(LPWSAPOLLFD fdarray, ULONG nfds, INT timeout); -#endif /* override configure because we are not using Makefiles */ #define LWS_NO_FORK