CMake support + fixed windows build. 02/3002/1
authorJoakim Soderberg <joakim.soderberg@gmail.com>
Wed, 6 Feb 2013 06:26:58 +0000 (15:26 +0900)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Thu, 7 Mar 2013 21:01:30 +0000 (13:01 -0800)
- Finalized CMake support (tested on windows only so far).
  - Uses a generated lws_config.h that is included in
  private-libwebsocket to pass defines, only used if CMAKE_BUILD is set.
  - Support for SSL on Windows.
  - Initial support for CyaSSL replacement of OpenSSL (This has been added
    to my older CMake-fork but haven't been tested on this version yet).
- Fixed windows build (see below for details).
- Fixed at least the 32-bit Debug build for the existing Visual Studio
  Project. (Not to keen fixing all the others when we have CMake support
  anyway (which can generate much better project files)...)
- BUGFIXES:
  - handshake.c
    - used C99 definition of handshake_0405 function
  - libwebsocket.c
    - syslog not available on windows, put in ifdefs.
    - Fixed previous known crash bug on Windows where WSAPoll in
      Ws2_32.dll would not be present, causing the poll function pointer
      being set to NULL.
    - Uninitialized variable context->listen_service_extraseen would
      result in stack overflow because of infinite recursion. Fixed by
      initializing in libwebsocket_create_context
    - SO_REUSADDR means something different on Windows compared to Unix.
    - Setting a socket to nonblocking is done differently on Windows.
      (This should probably broken out into a helper function instead)
    - lwsl_emit_syslog -> lwsl_emit_stderr on Windows.
  - private-libwebsocket.h
    - PATH_MAX is not available on Windows, define as MAX_PATH
    - Always define LWS_NO_DAEMONIZE on windows.
    - Don't define lws_latency as inline that does nothing. inline is not
      support by the Microsoft compiler, replaced with an empty define
      instead. (It's __inline in MSVC)
  - server.c
    - Fixed nonblock call on windows
  - test-ping.c
    - Don't use C99 features (Microsoft compiler does not support it).
    - Move non-win32 headers into ifdefs.
    - Skip use of sighandler on Windows.
  - test-server.c
    - ifdef syslog parts on Windows.

12 files changed:
CMakeLists.txt
cmake/FindOpenSSLbins.cmake [new file with mode: 0644]
config.h.cmake
lib/base64-decode.c
lib/handshake.c
lib/libwebsockets.c
lib/private-libwebsockets.h
lib/server.c
test-server/test-ping.c
test-server/test-server.c
win32port/libwebsocketswin32/libwebsocketswin32.vcxproj
win32port/libwebsocketswin32/libwebsocketswin32.vcxproj.filters

index aa8e9e6..42679a6 100644 (file)
@@ -11,8 +11,23 @@ set(PACKAGE_TARNAME "${PACKAGE}")
 set(PACKAGE_URL "http://libwebsockets.org")
 set(VERSION "{PACKAGE_VERSION}")
 
+set(LWS_LIBRARY_VERSION ${PACKAGE_VERSION})
+
+# Try to find the current Git hash.
+find_package(Git)
+if(GIT_EXECUTABLE)
+       execute_process(
+    COMMAND "${GIT_EXECUTABLE}" log -n 1 --pretty=%h
+    OUTPUT_VARIABLE GIT_HASH
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+
+    set(LWS_BUILD_HASH ${GIT_HASH})
+    message("Git commit hash: ${LWS_BUILD_HASH}")
+endif()
+
 option(WITH_SSL "Include SSL support (default OpenSSL, CyaSSL if USE_CYASSL is set)" ON)
-option(USE_INCLUDED_WIN32_ZLIB "Use the internal version of ZLib instead of searching the system" ON)
+option(USE_EXTERNAL_ZLIB "Search the system for ZLib instead of using the included one (on Windows)" OFF)
 option(USE_CYASSL "Use CyaSSL replacement for OpenSSL" OFF)
 option(WITH_BUILTIN_GETIFADDRS "Use BSD getifaddrs implementation from libwebsockets... default is your libc provides it" OFF)
 option(WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF)
@@ -34,6 +49,16 @@ endif()
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
 include_directories(${PROJECT_BINARY_DIR})
 
+# Put the libaries and binaries that get built into directories at the
+# top of the build tree rather than in hard-to-find leaf directories. 
+SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
+SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
+SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
+
+# So we can include the CMake generated config file only when
+# building with CMAKE.
+add_definitions(-DCMAKE_BUILD)
+
 include(CheckFunctionExists)
 include(CheckIncludeFile)
 include(CheckIncludeFiles)
@@ -49,6 +74,10 @@ CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
 CHECK_FUNCTION_EXISTS(vfork HAVE_VFORK)
 CHECK_FUNCTION_EXISTS(getifaddrs HAVE_GETIFADDRS)
 
+if (HAVE_GETIFADDRS AND WITH_BUILTIN_GETIFADDRS)
+       warning("getifaddrs already exists on the system, are you sure you want to build using the BSD version? (This is normally only needed on systems running uclibc)")
+endif()
+
 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
 CHECK_INCLUDE_FILE(fcntl.h HAVE_FCNTL_H)
 CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H)
@@ -92,7 +121,7 @@ endif()
 # Generate the config.h that includes all the compilation settings.
 configure_file(
                ${PROJECT_SOURCE_DIR}/config.h.cmake 
-               ${PROJECT_BINARY_DIR}/config.h)
+               ${PROJECT_BINARY_DIR}/lws_config.h)
 
 set(LIB_LIST)
 
@@ -101,17 +130,16 @@ if (MSVC)
        add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
 endif()
 
-if (WIN32)
-       # For windows, do not allow the compiler to use default target (Vista).
-       add_definitions(-D_WIN32_WINNT=0x0501)
-endif(WIN32)
+include_directories(${PROJECT_SOURCE_DIR}/lib)
 
 # Group headers and sources.
 # Some IDEs use this for nicer file structure.
 set(HDR_PRIVATE
        lib/private-libwebsockets.h
        lib/extension-deflate-frame.h
-       lib/lib/extension-deflate-stream.h)
+       lib/extension-deflate-stream.h
+       ${PROJECT_BINARY_DIR}/lws_config.h
+       )
 
 set(HDR_PUBLIC 
        lib/libwebsockets.h
@@ -122,7 +150,6 @@ set(SOURCES
        lib/client.c
        lib/client-handshake.c
        lib/client-parser.c
-       lib/daemonize.c
        lib/extension.c
        lib/extension-deflate-frame.c
        lib/extension-deflate-stream.c
@@ -138,7 +165,7 @@ set(SOURCES
 
 # Add helper files for Windows.
 if (WIN32)
-       set(WIN32_HELPERS_PATH ${PROJECT_SOURCE_DIR}/win32port/win32helpers)
+       set(WIN32_HELPERS_PATH win32port/win32helpers)
 
        list(APPEND HDR_PRIVATE
                ${WIN32_HELPERS_PATH}/websock-w32.h
@@ -149,6 +176,13 @@ if (WIN32)
                ${WIN32_HELPERS_PATH}/websock-w32.c
                ${WIN32_HELPERS_PATH}/gettimeofday.c
                )
+
+       include_directories(${WIN32_HELPERS_PATH})
+else()
+       # Unix.
+       list(APPEND SOURCES
+               lib/daemonize.c
+               )
 endif()
 
 if (UNIX)
@@ -177,41 +211,43 @@ add_library(websocket STATIC
 #
 # ZLIB.
 #
-if (WIN32 AND USE_INCLUDED_WIN32_ZLIB)
+if (WIN32 AND NOT USE_EXTERNAL_ZLIB)
+       message("Using included Zlib version")
+
        # Compile ZLib if needed.
-       if (USE_INCLUDED_WIN32_ZLIB)
-               set(WIN32_ZLIB_PATH "${PROJECT_SOURCE_DIR}/win32port/zlib")
-               set(ZLIB_SRCS
-                       ${WIN32_ZLIB_PATH}/adler32.c
-                       ${WIN32_ZLIB_PATH}/compress.c
-                       ${WIN32_ZLIB_PATH}/crc32.c
-                       ${WIN32_ZLIB_PATH}/deflate.c
-                       ${WIN32_ZLIB_PATH}/gzclose.c
-                       ${WIN32_ZLIB_PATH}/gzio.c
-                       ${WIN32_ZLIB_PATH}/gzlib.c
-                       ${WIN32_ZLIB_PATH}/gzread.c
-                       ${WIN32_ZLIB_PATH}/gzwrite.c
-                       ${WIN32_ZLIB_PATH}/infback.c
-                       ${WIN32_ZLIB_PATH}/inffast.c
-                       ${WIN32_ZLIB_PATH}/inflate.c
-                       ${WIN32_ZLIB_PATH}/inftrees.c
-                       ${WIN32_ZLIB_PATH}/trees.c
-                       ${WIN32_ZLIB_PATH}/uncompr.c
-                       ${WIN32_ZLIB_PATH}/zutil.c
-               )
+       set(WIN32_ZLIB_PATH "win32port/zlib")
+       set(ZLIB_SRCS
+               ${WIN32_ZLIB_PATH}/adler32.c
+               ${WIN32_ZLIB_PATH}/compress.c
+               ${WIN32_ZLIB_PATH}/crc32.c
+               ${WIN32_ZLIB_PATH}/deflate.c
+               ${WIN32_ZLIB_PATH}/gzclose.c
+               ${WIN32_ZLIB_PATH}/gzio.c
+               ${WIN32_ZLIB_PATH}/gzlib.c
+               ${WIN32_ZLIB_PATH}/gzread.c
+               ${WIN32_ZLIB_PATH}/gzwrite.c
+               ${WIN32_ZLIB_PATH}/infback.c
+               ${WIN32_ZLIB_PATH}/inffast.c
+               ${WIN32_ZLIB_PATH}/inflate.c
+               ${WIN32_ZLIB_PATH}/inftrees.c
+               ${WIN32_ZLIB_PATH}/trees.c
+               ${WIN32_ZLIB_PATH}/uncompr.c
+               ${WIN32_ZLIB_PATH}/zutil.c
+       )
 
-               # Create the library.
-               add_library(zlib STATIC ${ZLIB_SRCS})
+       # Create the library.
+       add_library(zlib STATIC ${ZLIB_SRCS})
 
-               # Set the same variables as find_package would.
-               set(${ZLIB_INCLUDE_DIRS} ${WIN32_ZLIB_PATH})
-               get_property(ZLIB_LIBRARIES TARGET zlib PROPERTY LOCATION)
-               set(ZLIB_FOUND 1)
-       endif()
+       # Set the same variables as find_package would.
+       set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH})
+       get_property(ZLIB_LIBRARIES TARGET zlib PROPERTY LOCATION)
+       set(ZLIB_FOUND 1)
 else()
        find_package(zlib REQUIRED)
 endif()
 
+message("ZLib include dirs: ${ZLIB_INCLUDE_DIRS}")
+message("ZLib libraries: ${ZLIB_LIBRARIES}")
 include_directories(${ZLIB_INCLUDE_DIRS})
 target_link_libraries(websocket ${ZLIB_LIBRARIES})
 
@@ -219,6 +255,8 @@ target_link_libraries(websocket ${ZLIB_LIBRARIES})
 # OpenSSL
 #
 if (WITH_SSL)
+       message("Compiling with SSL support")
+
        if (USE_CYASSL)
                # Use CyaSSL as OpenSSL replacement.
                set(OPENSSL_LIBRARIES ${CYASSL_LIB})
@@ -227,10 +265,128 @@ if (WITH_SSL)
        else()
                # TODO: Add support for STATIC also.
                find_package(OpenSSL REQUIRED)
+
+               # TODO: Find OpenSSL binaries and copy them to the output directories for the test-apps so that they can be run out of the box.
        endif()
 
+       message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
+       message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
        include_directories(${OPENSSL_INCLUDE_DIR})
        target_link_libraries(websocket ${OPENSSL_LIBRARIES})
+endif(WITH_SSL)
+
+#
+# Platform specific libs.
+#
+if (WIN32)
+       target_link_libraries(websocket ws2_32.lib)
 endif()
 
+if (UNIX)
+       target_link_libraries(websocket m)
+endif()
 
+#
+# Test applications
+#
+if (NOT WITHOUT_TESTAPPS)
+       #
+       # Helper function for adding a test app.
+       #
+       function(create_test_app TEST_NAME MAIN_SRC WIN32_SRCS WIN32_HDRS)
+               
+               set(TEST_CLIENT_NAME test-client)
+               set(TEST_SRCS ${MAIN_SRC})
+               set(TEST_HDR)
+
+               if (WIN32)
+                       list(APPEND TEST_SRCS 
+                               ${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"   FILES ${TEST_HDR})
+               source_group("Sources"   FILES ${TEST_SRCS})
+               add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR})
+               target_link_libraries(${TEST_NAME} websocket)
+       endfunction()
+
+       #
+       # test-client
+       #
+       if (NOT WITHOUT_CLIENT)
+               create_test_app(test-client
+                       "test-server/test-client.c"
+                       ""
+                       "")
+       endif(NOT WITHOUT_CLIENT)
+
+       #
+       # test-server
+       #
+       if (NOT WITHOUT_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")
+       endif(NOT WITHOUT_SERVER)
+
+       #
+       # test-fraggle
+       #
+       if (NOT WITHOUT_FRAGGLE)
+               create_test_app(test-fraggle
+                       "test-server/test-fraggle.c"
+                       ""
+                       "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h")
+       endif(NOT WITHOUT_FRAGGLE)
+
+       #
+       # test-ping
+       #
+       if (NOT WITHOUT_PING)
+               create_test_app(test-ping
+                       "test-server/test-ping.c"
+                       ""
+                       "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h")
+       endif(NOT WITHOUT_PING)
+
+       #
+       # Copy OpenSSL dlls to the output directory on Windows.
+       # (Otherwise we'll get an error when trying to run)
+       #
+       if (WIN32 AND WITH_SSL AND NOT USE_CYASSL)
+
+               message("Searching for OpenSSL dlls")
+               find_package(OpenSSLbins)
+
+               if(OPENSSL_BIN_FOUND)
+                       message("OpenSSL dlls found, copying to output directory")
+                       message("Libeay: ${LIBEAY_BIN}")
+                       message("SSLeay: ${SSLEAY_BIN}")
+
+                       foreach(TARGET_BIN 
+                                       test-client 
+                                       test-server
+                                       test-fraggle
+                                       test-echo
+                                       test-ping
+                                       )                       
+                               add_custom_command(TARGET ${TARGET_BIN}
+                                       POST_BUILD 
+                                       COMMAND ${CMAKE_COMMAND} -E copy ${LIBEAY_BIN} $<TARGET_FILE_DIR:${TARGET_BIN}> VERBATIM)
+                                       
+                               add_custom_command(TARGET ${TARGET_BIN}
+                                       POST_BUILD 
+                                       COMMAND ${CMAKE_COMMAND} -E copy ${SSLEAY_BIN} $<TARGET_FILE_DIR:${TARGET_BIN}> VERBATIM)
+                       endforeach()
+               endif()
+       endif()
+endif(NOT WITHOUT_TESTAPPS)
diff --git a/cmake/FindOpenSSLbins.cmake b/cmake/FindOpenSSLbins.cmake
new file mode 100644 (file)
index 0000000..6516e59
--- /dev/null
@@ -0,0 +1,33 @@
+
+# On Windows, we need to copy the OpenSSL dlls to the output directory, so find them here.
+if(OPENSSL_FOUND)
+       
+       if(WIN32)
+               set(OPENSSL_BIN_FOUND 0)
+       
+               # Find the .dll files so we can copy them to the output directory.
+               find_file(LIBEAY_BIN
+                       NAMES
+                       libeay32.dll
+                       HINTS
+                       ${_OPENSSL_ROOT_HINTS}
+                       PATH_SUFFIXES
+                       bin)
+               
+               find_file(SSLEAY_BIN
+                       NAMES
+                       ssleay32.dll
+                       HINTS
+                       ${_OPENSSL_ROOT_HINTS}
+                       PATH_SUFFIXES
+                       bin)
+               
+               if(LIBEAY_BIN)
+                       if(SSLEAY_BIN)
+                               set(OPENSSL_BIN_FOUND 1)
+                       endif(SSLEAY_BIN)
+               endif(LIBEAY_BIN)
+       endif(WIN32)
+               
+endif(OPENSSL_FOUND)
+
index f2087ac..daac4d0 100644 (file)
@@ -1,7 +1,18 @@
 /* config.h.in.  Generated from configure.ac by autoheader.  */
 
+/* Define to 1 to use CyaSSL as a replacement for OpenSSL. 
+ * LWS_OPENSSL_SUPPORT needs to be set also for this to work. */
 #cmakedefine USE_CYASSL
 
+/* The Libwebsocket version */
+#cmakedefine LWS_LIBRARY_VERSION "${LWS_LIBRARY_VERSION}"
+
+/* The current git commit hash that we're building from */
+#cmakedefine LWS_BUILD_HASH "${LWS_BUILD_HASH}"
+
+/* build with OpenSSL support */
+#cmakedefine LWS_OPENSSL_SUPPORT
+
 /* Define to 1 if you have the `bzero' function. */
 #cmakedefine HAVE_BZERO
 
index 3baab3b..2545d40 100644 (file)
@@ -41,7 +41,7 @@
 
 #include <stdio.h>
 #include <string.h>
-#include <private-libwebsockets.h>
+#include "private-libwebsockets.h"
 
 static const char encode[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                             "abcdefghijklmnopqrstuvwxyz0123456789+/";
index 72f51d4..7cb2799 100644 (file)
  * machine that is completely independent of packet size.
  */
 
+#ifndef LWS_NO_SERVER
+extern int handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi);
+#endif
+
 int
 libwebsocket_read(struct libwebsocket_context *context,
                     struct libwebsocket *wsi, unsigned char * buf, size_t len)
@@ -94,8 +98,6 @@ libwebsocket_read(struct libwebsocket_context *context,
 #ifndef LWS_NO_SERVER
                /* LWS_CONNMODE_WS_SERVING */
 
-               extern int handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi);
-
                for (n = 0; n < len; n++)
                        libwebsocket_parse(wsi, *buf++);
 
index 4ed528a..17fd7ef 100644 (file)
@@ -20,7 +20,6 @@
  */
 
 #include "private-libwebsockets.h"
-#include <syslog.h>
 
 #ifdef WIN32
 #include <tchar.h>
@@ -31,6 +30,7 @@
 #else
 #include <ifaddrs.h>
 #endif
+#include <syslog.h>
 #include <sys/un.h>
 #include <sys/socket.h>
 #include <netdb.h>
@@ -748,9 +748,11 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
        if (context->last_timeout_check_s != tv.tv_sec) {
                context->last_timeout_check_s = tv.tv_sec;
 
+               #ifndef WIN32
                /* if our parent went down, don't linger around */
                if (context->started_with_parent && kill(context->started_with_parent, 0) < 0)
                        kill(getpid(), SIGTERM);
+               #endif
 
                /* global timeout check once per second */
 
@@ -1510,6 +1512,10 @@ libwebsocket_create_context(int port, const char *interf,
        char ssl_err_buf[512];
 #endif
 
+#ifndef LWS_NO_DAEMONIZE
+       extern int pid_daemon;
+#endif
+
        lwsl_notice("Initial logging level %d\n", log_level);
        lwsl_notice("Library version: %s\n", library_version);
        lwsl_info(" LWS_MAX_HEADER_NAME_LENGTH: %u\n", LWS_MAX_HEADER_NAME_LENGTH);
@@ -1554,6 +1560,9 @@ libwebsocket_create_context(int port, const char *interf,
                wsdll = GetModuleHandle(_T("Ws2_32.dll"));
                if (wsdll)
                        poll = (PFNWSAPOLL)GetProcAddress(wsdll, "WSAPoll");
+
+               if (!poll)
+                       poll = emulated_poll;
        }
 #endif
 
@@ -1563,11 +1572,11 @@ libwebsocket_create_context(int port, const char *interf,
                return NULL;
        }
 #ifndef LWS_NO_DAEMONIZE
-       extern int pid_daemon;
        context->started_with_parent = pid_daemon;
        lwsl_notice(" Started with daemon pid %d\n", pid_daemon);
 #endif
-
+       
+       context->listen_service_extraseen = 0;
        context->protocols = protocols;
        context->listen_port = port;
        context->http_proxy_port = 0;
@@ -1871,16 +1880,26 @@ libwebsocket_create_context(int port, const char *interf,
                        return NULL;
                }
 
-               /* allow us to restart even if old sockets in TIME_WAIT */
+#ifndef WIN32
+               /* allow us to restart even if old sockets in TIME_WAIT
+                * (REUSEADDR on Unix means, "don't hang on to this address after the
+                * listener is closed."  On Windows, though, it means "don't keep other
+                * processes from binding to this address while we're using it) */
                setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
                                              (const void *)&opt, sizeof(opt));
+#endif
 
                /* Disable Nagle */
                opt = 1;
                setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY,
                                              (const void *)&opt, sizeof(opt));
 
+               #ifdef WIN32
+               opt = 0;
+               ioctlsocket(sockfd, FIONBIO, (unsigned long *)&opt );
+               #else
                fcntl(sockfd, F_SETFL, O_NONBLOCK);
+               #endif
 
                bzero((char *) &serv_addr, sizeof(serv_addr));
                serv_addr.sin_family = AF_INET;
@@ -2041,6 +2060,12 @@ static void lwsl_emit_stderr(int level, const char *line)
        fprintf(stderr, "%s%s", buf, line);
 }
 
+#ifdef WIN32
+void lwsl_emit_syslog(int level, const char *line)
+{
+       lwsl_emit_stderr(level, line);
+}
+#else
 void lwsl_emit_syslog(int level, const char *line)
 {
        int syslog_level = LOG_DEBUG;
@@ -2061,6 +2086,7 @@ void lwsl_emit_syslog(int level, const char *line)
        }
        syslog(syslog_level, "%s", line);
 }
+#endif
 
 void _lws_log(int filter, const char *format, ...)
 {
index 7c62e07..769f2a7 100644 (file)
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  *  MA  02110-1301  USA
  */
+#ifdef CMAKE_BUILD
+#include "lws_config.h"
+#endif
+
 #if _MSC_VER > 1000 || defined(_WIN32)
 #else
 #include <unistd.h>
 #include <sys/stat.h>
 
 #ifdef WIN32
+#define LWS_NO_DAEMONIZE
+
+#ifndef PATH_MAX
+#define PATH_MAX MAX_PATH
+#endif
+
 #define compatible_close(fd) closesocket(fd);
 #ifdef  __MINGW64__                                                             
 #else                                                                           
@@ -380,8 +390,8 @@ struct libwebsocket {
 };
 
 #ifndef LWS_LATENCY
-static inline void lws_latency(struct libwebsocket_context *context, struct libwebsocket *wsi, const char *action, int ret, int completion) { while (0); }
-static inline void lws_latency_pre(struct libwebsocket_context *context, struct libwebsocket *wsi) { while (0); }
+#define lws_latency(context, wsi, action, ret, completion)
+#define lws_latency_pre(context, wsi)
 #else
 #define lws_latency_pre(_context, _wsi) lws_latency(_context, _wsi, NULL, 0, 0)
 extern void
index 381f23a..b30d4e9 100644 (file)
@@ -233,7 +233,12 @@ int lws_server_socket_service(struct libwebsocket_context *context,
                                              (const void *)&opt, sizeof(opt));
 
                /* We are nonblocking... */
+               #ifdef WIN32
+               opt = 0;
+               ioctlsocket(accept_fd, FIONBIO, (unsigned long *)&opt );
+               #else
                fcntl(accept_fd, F_SETFL, O_NONBLOCK);
+               #endif
 
                /*
                 * look at who we connected to and give user code a chance
index ec2df1f..f83fe92 100644 (file)
 
 #include <sys/time.h>
 #include <sys/types.h>
+#ifndef WIN32
 #include <sys/socket.h>
-#include <netdb.h>
-
 #include <sys/ioctl.h>
+#include <poll.h>
+#endif
+
+#include <netdb.h>
 
 #include "../lib/libwebsockets.h"
-#include <poll.h>
 
 /*
  * this is specified in the 04 standard, control frames can only have small
@@ -278,13 +280,13 @@ callback_lws_mirror(struct libwebsocket_context * this,
 
 static struct libwebsocket_protocols protocols[] = {
 
-       [PROTOCOL_LWS_MIRROR] = {
-               .name = "lws-mirror-protocol",
-               .callback = callback_lws_mirror,
-               .per_session_data_size = sizeof (struct per_session_data__ping),
+       {
+               "lws-mirror-protocol",
+               callback_lws_mirror,
+               sizeof (struct per_session_data__ping),
        },
-       [DEMO_PROTOCOL_COUNT] = {  /* end of list */
-               .callback = NULL
+       { 
+               NULL, NULL, 0/* end of list */          
        }
 };
 
@@ -304,7 +306,7 @@ static struct option options[] = {
        { NULL, 0, 0, 0 }
 };
 
-
+#ifndef WIN32
 static void
 signal_handler(int sig, siginfo_t *si, void *v)
 {
@@ -313,7 +315,7 @@ signal_handler(int sig, siginfo_t *si, void *v)
        gettimeofday(&tv, NULL);
        interrupted_time = (tv.tv_sec * 1000000) + tv.tv_usec;
 }
-
+#endif
 
 int main(int argc, char **argv)
 {
@@ -323,9 +325,11 @@ int main(int argc, char **argv)
        struct libwebsocket_context *context;
        char protocol_name[256];
        char ip[30];
+#ifndef WIN32
        struct sigaction sa;
-       struct timeval tv;
        struct winsize w;
+#endif
+       struct timeval tv;
        unsigned long oldus = 0;
        unsigned long l;
        int ietf_version = -1;
@@ -401,11 +405,12 @@ int main(int argc, char **argv)
                }
        }
 
-
+#ifndef WIN32
        if (isatty(STDOUT_FILENO))
                if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1)
                        if (w.ws_col > 0)
                                screen_width = w.ws_col;
+#endif
 
        context = libwebsocket_create_context(CONTEXT_PORT_NO_LISTEN, NULL,
                                              protocols,
@@ -441,12 +446,13 @@ int main(int argc, char **argv)
        fprintf(stderr, "Websocket PING %s (%s) %d bytes of data.\n",
                                                           peer_name, ip, size);
 
+#ifndef WIN32
        /* set the ^C handler */
-
        sa.sa_sigaction = signal_handler;
        sa.sa_flags = SA_SIGINFO;
        sigemptyset(&sa.sa_mask);
        sigaction(SIGINT, &sa, NULL);
+#endif
 
        gettimeofday(&tv, NULL);
        started = (tv.tv_sec * 1000000) + tv.tv_usec;
index cccefd4..d773fff 100644 (file)
@@ -26,7 +26,9 @@
 #include <string.h>
 #include <sys/time.h>
 #include <assert.h>
+#ifndef WIN32
 #include <syslog.h>
+#endif
 #include <signal.h>
 
 #include "../lib/libwebsockets.h"
@@ -496,7 +498,9 @@ int main(int argc, char **argv)
        int opts = 0;
        char interface_name[128] = "";
        const char *interface = NULL;
+#ifndef WIN32
        int syslog_options = LOG_PID | LOG_PERROR;
+#endif
        unsigned int oldus = 0;
 
        int debug_level = 7;
@@ -512,7 +516,9 @@ int main(int argc, char **argv)
 #ifndef LWS_NO_DAEMONIZE
                case 'D':
                        daemonize = 1;
+                       #ifndef WIN32
                        syslog_options &= ~LOG_PERROR;
+                       #endif
                        break;
 #endif
                case 'd':
@@ -543,7 +549,7 @@ int main(int argc, char **argv)
                }
        }
 
-#ifndef LWS_NO_DAEMONIZE
+#if !defined(LWS_NO_DAEMONIZE) && !defined(WIN32)
        /* 
         * normally lock path would be /var/lock/lwsts or similar, to
         * simplify getting started without having to take care about
@@ -557,9 +563,11 @@ int main(int argc, char **argv)
 
        signal(SIGINT, sighandler);
 
+#ifndef WIN32
        /* we will only try to log things according to our debug_level */
        setlogmask(LOG_UPTO (LOG_DEBUG));
        openlog("lwsts", syslog_options, LOG_DAEMON);
+#endif
 
        /* tell the library what debug level to emit and to send it to syslog */
        lws_set_log_level(debug_level, lwsl_emit_syslog);
@@ -653,7 +661,9 @@ done:
 
        lwsl_notice("libwebsockets-test-server exited cleanly\n");
 
+#ifndef WIN32
        closelog();
+#endif
 
        return 0;
 }
index e199c14..7678766 100644 (file)
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <LibraryPath>D:\Libraries\libwebsockets\output\;$(LibraryPath)</LibraryPath>
+    <IncludePath>lib;$(IncludePath)</IncludePath>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <LibraryPath>D:\Libraries\libwebsockets\output\;$(LibraryPath)</LibraryPath>
       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;LWS_LIBRARY_VERSION="1.1";%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <AdditionalIncludeDirectories>../win32helpers;../zlib</AdditionalIncludeDirectories>
       <ExceptionHandling>false</ExceptionHandling>
     </ClCompile>
   <ItemGroup>
     <ClCompile Include="..\..\lib\base64-decode.c" />
     <ClCompile Include="..\..\lib\client-handshake.c" />
+    <ClCompile Include="..\..\lib\client-parser.c" />
+    <ClCompile Include="..\..\lib\client.c" />
     <ClCompile Include="..\..\lib\extension-deflate-frame.c" />
     <ClCompile Include="..\..\lib\extension-deflate-stream.c" />
     <ClCompile Include="..\..\lib\extension.c" />
     <ClCompile Include="..\..\lib\handshake.c" />
     <ClCompile Include="..\..\lib\libwebsockets.c" />
-    <ClCompile Include="..\..\lib\md5.c" />
+    <ClCompile Include="..\..\lib\minilex.c" />
+    <ClCompile Include="..\..\lib\output.c" />
     <ClCompile Include="..\..\lib\parsers.c" />
+    <ClCompile Include="..\..\lib\server-handshake.c" />
+    <ClCompile Include="..\..\lib\server.c" />
     <ClCompile Include="..\..\lib\sha-1.c" />
     <ClCompile Include="..\win32helpers\gettimeofday.c" />
     <ClCompile Include="..\win32helpers\websock-w32.c" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
index 05ff11a..f90a232 100644 (file)
@@ -27,9 +27,6 @@
     <ClCompile Include="..\..\lib\libwebsockets.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\lib\md5.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\lib\parsers.c">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="..\..\lib\extension-deflate-frame.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\lib\server-handshake.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\lib\client.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\lib\client-parser.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\lib\minilex.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\lib\output.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\lib\server.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\lib\libwebsockets.h">
@@ -75,4 +90,4 @@
       <Filter>Header Files</Filter>
     </ClInclude>
   </ItemGroup>
-</Project>
+</Project>
\ No newline at end of file