Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various Windows Cleanup #95

Merged
merged 6 commits into from Mar 30, 2014
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -296,15 +296,6 @@ endif()
# Add helper files for Windows.
if (WIN32)
set(WIN32_HELPERS_PATH win32port/win32helpers)

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.
@@ -498,7 +489,7 @@ if (NOT LWS_WITHOUT_TESTAPPS)
#
# Helper function for adding a test app.
#
macro(create_test_app TEST_NAME MAIN_SRC WIN32_SRCS WIN32_HDRS)
macro(create_test_app TEST_NAME MAIN_SRC)

set(TEST_SRCS ${MAIN_SRC})
set(TEST_HDR)
@@ -508,12 +499,12 @@ if (NOT LWS_WITHOUT_TESTAPPS)
${WIN32_HELPERS_PATH}/getopt.c
${WIN32_HELPERS_PATH}/getopt_long.c
${WIN32_HELPERS_PATH}/gettimeofday.c
${WIN32_SRCS})
)

list(APPEND TEST_HDR
${WIN32_HELPERS_PATH}/getopt.h
${WIN32_HELPERS_PATH}/gettimeofday.h
${WIN32_HDRS})
)
endif(WIN32)

source_group("Headers Private" FILES ${TEST_HDR})
@@ -554,20 +545,14 @@ if (NOT LWS_WITHOUT_TESTAPPS)
# test-server
#
if (NOT LWS_WITHOUT_TEST_SERVER)
create_test_app(test-server
"test-server/test-server.c"
""
"${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h")
create_test_app(test-server "test-server/test-server.c")
endif()

#
# test-server-extpoll
#
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")
create_test_app(test-server-extpoll "test-server/test-server.c")
# Set defines for this executable only.
set_property(
TARGET test-server-extpoll
@@ -663,39 +648,27 @@ if (NOT LWS_WITHOUT_TESTAPPS)
# test-client
#
if (NOT LWS_WITHOUT_TEST_CLIENT)
create_test_app(test-client
"test-server/test-client.c"
""
"")
create_test_app(test-client "test-server/test-client.c")
endif()

#
# test-fraggle
#
if (NOT LWS_WITHOUT_TEST_FRAGGLE)
create_test_app(test-fraggle
"test-server/test-fraggle.c"
""
"${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h")
create_test_app(test-fraggle "test-server/test-fraggle.c")
endif()

#
# test-ping
#
if (NOT LWS_WITHOUT_TEST_PING)
create_test_app(test-ping
"test-server/test-ping.c"
""
"${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h")
create_test_app(test-ping "test-server/test-ping.c")
endif()
#
# test-echo
#
if (NOT WITHOUT_TEST_ECHO)
create_test_app(test-echo
"test-server/test-echo.c"
""
"${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h")
create_test_app(test-echo "test-server/test-echo.c")
endif()

endif(NOT LWS_WITHOUT_CLIENT)
@@ -4,7 +4,7 @@ struct libwebsocket *libwebsocket_client_connect_2(
struct libwebsocket_context *context,
struct libwebsocket *wsi
) {
struct pollfd pfd;
struct libwebsocket_pollfd pfd;
#ifdef LWS_USE_IPV6
struct sockaddr_in6 server_addr6;
struct sockaddr_in6 client_addr6;
@@ -35,7 +35,7 @@
#endif

int lws_client_socket_service(struct libwebsocket_context *context,
struct libwebsocket *wsi, struct pollfd *pollfd)
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd)
{
int n;
char *p = (char *)&context->service_buffer[0];
@@ -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
@@ -87,12 +79,12 @@ static const char * const log_level_names[] = {
#ifndef LWS_NO_CLIENT
extern int lws_client_socket_service(
struct libwebsocket_context *context,
struct libwebsocket *wsi, struct pollfd *pollfd);
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd);
#endif
#ifndef LWS_NO_SERVER
extern int lws_server_socket_service(
struct libwebsocket_context *context,
struct libwebsocket *wsi, struct pollfd *pollfd);
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd);
#endif


@@ -776,7 +768,7 @@ LWS_VISIBLE int lws_send_pipe_choked(struct libwebsocket *wsi)
#ifdef _WIN32
return wsi->sock_send_blocking;
#else
struct pollfd fds;
struct libwebsocket_pollfd fds;

/* treat the fact we got a truncated send pending as if we're choked */
if (wsi->truncated_send_len)
@@ -800,7 +792,7 @@ LWS_VISIBLE int lws_send_pipe_choked(struct libwebsocket *wsi)

int
lws_handle_POLLOUT_event(struct libwebsocket_context *context,
struct libwebsocket *wsi, struct pollfd *pollfd)
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd)
{
int n;

@@ -986,7 +978,7 @@ libwebsocket_service_timeout_check(struct libwebsocket_context *context,
return 0;
}

static int lws_poll_listen_fd(struct pollfd* fd)
static int lws_poll_listen_fd(struct libwebsocket_pollfd* fd)
{
#ifdef _WIN32
fd_set readfds;
@@ -1028,7 +1020,7 @@ static int lws_poll_listen_fd(struct pollfd* fd)

LWS_VISIBLE int
libwebsocket_service_fd(struct libwebsocket_context *context,
struct pollfd *pollfd)
struct libwebsocket_pollfd *pollfd)
{
struct libwebsocket *wsi;
int n;
@@ -1326,7 +1318,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
LWS_VISIBLE void
libwebsocket_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
{
struct pollfd eventfd;
struct libwebsocket_pollfd eventfd;
struct lws_io_watcher *lws_io = (struct lws_io_watcher*)watcher;
struct libwebsocket_context *context = lws_io->context;

@@ -1506,7 +1498,7 @@ libwebsocket_service(struct libwebsocket_context *context, int timeout_ms)
int i;
DWORD ev;
WSANETWORKEVENTS networkevents;
struct pollfd *pfd;
struct libwebsocket_pollfd *pfd;
#else
int m;
char buf;
@@ -1738,7 +1730,7 @@ lws_change_pollfd(struct libwebsocket *wsi, int _and, int _or)
struct libwebsocket_context *context = wsi->protocol->owning_server;
int tid;
int sampled_tid;
struct pollfd *pfd;
struct libwebsocket_pollfd *pfd;
struct libwebsocket_pollargs pa;
#ifdef _WIN32
long networkevents = FD_WRITE;
@@ -2234,7 +2226,6 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
WORD wVersionRequested;
WSADATA wsaData;
int err;
HMODULE wsdll;

/* Use the MAKEWORD(lowbyte, highbyte) macro from Windef.h */
wVersionRequested = MAKEWORD(2, 2);
@@ -2272,13 +2263,13 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
context->max_fds = getdtablesize();
lwsl_notice(" static allocation: %u + (%u x %u fds) = %u bytes\n",
sizeof(struct libwebsocket_context),
sizeof(struct pollfd) + sizeof(struct libwebsocket *),
sizeof(struct libwebsocket_pollfd) + sizeof(struct libwebsocket *),
context->max_fds,
sizeof(struct libwebsocket_context) +
((sizeof(struct pollfd) + sizeof(struct libwebsocket *)) *
((sizeof(struct libwebsocket_pollfd) + sizeof(struct libwebsocket *)) *
context->max_fds));

context->fds = (struct pollfd *)malloc(sizeof(struct pollfd) *
context->fds = (struct libwebsocket_pollfd *)malloc(sizeof(struct libwebsocket_pollfd) *
context->max_fds);
if (context->fds == NULL) {
lwsl_err("Unable to allocate fds array for %d connections\n",
@@ -36,7 +36,6 @@ extern "C" {
#include <ws2tcpip.h>
#include <stddef.h>
#include <basetsd.h>
#include "websock-w32.h"

#define strcasecmp stricmp
#define getdtablesize() 30000
@@ -204,6 +203,15 @@ struct libwebsocket_pollargs {
int prev_events; // the previous event mask
};

#ifdef _WIN32
struct libwebsocket_pollfd {
SOCKET fd;
SHORT events;
SHORT revents;
};
#else
#define libwebsocket_pollfd pollfd
#endif

#ifndef LWS_NO_EXTENSIONS
enum libwebsocket_extension_callback_reasons {
@@ -990,7 +998,7 @@ libwebsocket_sigint_cb(

LWS_VISIBLE LWS_EXTERN int
libwebsocket_service_fd(struct libwebsocket_context *context,
struct pollfd *pollfd);
struct libwebsocket_pollfd *pollfd);

LWS_VISIBLE LWS_EXTERN void *
libwebsocket_context_user(struct libwebsocket_context *context);
@@ -70,6 +70,9 @@
#define LWS_EWOULDBLOCK WSAEWOULDBLOCK
#define LWS_POLLIN (FD_READ | FD_ACCEPT)
#define LWS_POLLOUT (FD_WRITE)
#define MSG_NOSIGNAL 0
#define SHUT_RDWR SD_BOTH
#define SOL_TCP IPPROTO_TCP

#define compatible_close(fd) closesocket(fd);
#ifdef __MINGW64__
@@ -82,6 +85,13 @@
#include <winsock2.h>
#include <windows.h>
#define LWS_INVALID_FILE INVALID_HANDLE_VALUE

#if defined(__MINGW32__) || defined(__MINGW64__) || _WIN32_WINNT < 0x0600
#define POLLIN 0x01
#define POLLOUT 0x04
#define POLLERR 0x08
#define POLLHUP 0x10
#endif
#else
#include <sys/types.h>
#include <sys/socket.h>
@@ -287,7 +297,7 @@ struct libwebsocket_context {
#ifdef _WIN32
WSAEVENT *events;
#endif
struct pollfd *fds;
struct libwebsocket_pollfd *fds;
struct libwebsocket **lws_lookup; /* fd to wsi */
int fds_count;
#ifdef LWS_USE_LIBEV
@@ -570,7 +580,7 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context,

LWS_EXTERN int
lws_handle_POLLOUT_event(struct libwebsocket_context *context,
struct libwebsocket *wsi, struct pollfd *pollfd);
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd);
#ifndef LWS_NO_EXTENSIONS
LWS_EXTERN int
lws_any_extension_handled(struct libwebsocket_context *context,
@@ -99,7 +99,7 @@ libwebsocket_create_new_server_wsi(struct libwebsocket_context *context)
}

int lws_server_socket_service(struct libwebsocket_context *context,
struct libwebsocket *wsi, struct pollfd *pollfd)
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd)
{
struct libwebsocket *new_wsi;
int accept_fd;
@@ -21,11 +21,16 @@

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <signal.h>

#ifdef _WIN32
#define random rand
#else
#include <unistd.h>
#endif

#ifdef CMAKE_BUILD
#include "lws_config.h"
#endif
@@ -24,16 +24,16 @@

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <sys/time.h>
#include <assert.h>
#ifdef WIN32
#else
#include <signal.h>

#ifndef _WIN32
#include <syslog.h>
#include <sys/time.h>
#include <unistd.h>
#endif
#include <signal.h>

#ifdef CMAKE_BUILD
#include "lws_config.h"
@@ -21,10 +21,15 @@

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>

#ifdef _WIN32
#define random rand
#else
#include <sys/time.h>
#include <unistd.h>
#endif

#ifdef CMAKE_BUILD
#include "lws_config.h"
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.