if (MINGW)
set(LWS_MINGW_SUPPORT 1)
+ set(CMAKE_C_FLAGS "-D__USE_MINGW_ANSI_STDIO ${CMAKE_C_FLAGS}")
endif()
include_directories("${PROJECT_BINARY_DIR}")
set(TEST_SERVER_SSL_CERT "${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem")
if (WIN32)
- file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt"
- "GB\n"
- "Erewhon\n"
- "All around\n"
- "libwebsockets-test\n"
- "localhost\n"
- "none@invalid.org\n\n"
- )
-
- # The "type" command is a bit picky with paths.
- file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH)
- message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}")
- message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
-
- execute_process(
- COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
- COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
- RESULT_VARIABLE OPENSSL_RETURN_CODE
- OUTPUT_QUIET ERROR_QUIET)
-
- message("\n")
+ if (MINGW)
+ message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -subj \"/C=GB/ST=Erewhon/L=All around/O=libwebsockets-test/CN=localhost\" -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
+ execute_process(
+ COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -subj "/C=GB/ST=Erewhon/L=All around/O=libwebsockets-test/CN=localhost" -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
+ RESULT_VARIABLE OPENSSL_RETURN_CODE)
+ else()
+ file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt"
+ "GB\n"
+ "Erewhon\n"
+ "All around\n"
+ "libwebsockets-test\n"
+ "localhost\n"
+ "none@invalid.org\n\n"
+ )
+
+ # The "type" command is a bit picky with paths.
+ file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH)
+ message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}")
+ message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
+
+ execute_process(
+ COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
+ COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
+ RESULT_VARIABLE OPENSSL_RETURN_CODE
+ OUTPUT_QUIET ERROR_QUIET)
+
+ message("\n")
+ endif()
if (OPENSSL_RETURN_CODE)
message(WARNING "!!! Failed to generate SSL certificate for Test Server using cmd.exe !!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
message("---------------------------------------------------------------------")
message(" Settings: (For more help do cmake -LH <srcpath>)")
message("---------------------------------------------------------------------")
-message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)")
+message(" LWS_WITH_STATIC = ${LWS_WITH_STATIC}")
+message(" LWS_WITH_SHARED = ${LWS_WITH_SHARED}")
+message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)")
message(" LWS_SSL_CLIENT_USE_OS_CA_CERTS = ${LWS_SSL_CLIENT_USE_OS_CA_CERTS}")
message(" LWS_USE_WOLFSSL = ${LWS_USE_WOLFSSL} (wolfSSL/CyaSSL replacement for OpenSSL)")
if (LWS_USE_WOLFSSL)
Libwebsockets has been tested to build successfully on the following platforms
with SSL support (both OpenSSL/wolfSSL):
-- Windows
+- Windows (Visual Studio)
+- Windows (MinGW)
- Linux (x86 and ARM)
- OSX
- NetBSD
$ make
```
-
Quirk of cmake
--------------
changes sometimes is delete the contents of your build directory and do the
cmake from scratch.
-
Building on Windows (Visual Studio)
-----------------------------------
1. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html
2. Install OpenSSL binaries. http://www.openssl.org/related/binaries.html
- (Preferably in the default location to make it easier for CMake to find them)
+ (**NOTE**: Preferably in the default location to make it easier for CMake to find them)
+
+ **NOTE2**:
+ Be sure that OPENSSL_CONF environment variable is defined and points at
+ <OpenSSL install location>\bin\openssl.cfg
+
3. Generate the Visual studio project by opening the Visual Studio cmd prompt:
```bash
```
(**NOTE**: There is also a cmake-gui available on Windows if you prefer that)
+
+ **NOTE2**:
+ See this link to find out the version number corresponding to your Visual Studio edition:
+ http://superuser.com/a/194065
4. Now you should have a generated Visual Studio Solution in your
`<path to src>/build` directory, which can be used to build.
+Building on Windows (MinGW)
+---------------------------
+1. Install MinGW: http://sourceforge.net/projects/mingw/files
+
+ (**NOTE**: Preferably in the default location C:\MinGW)
+
+2. Fix up MinGW headers
+
+ a) Add the following lines to C:\MinGW\include\winsock2.h:
+
+#if(_WIN32_WINNT >= 0x0600)
+
+typedef struct pollfd {
+
+ SOCKET fd;
+ SHORT events;
+ SHORT revents;
+
+} WSAPOLLFD, *PWSAPOLLFD, FAR *LPWSAPOLLFD;
+
+WINSOCK_API_LINKAGE int WSAAPI WSAPoll(LPWSAPOLLFD fdArray, ULONG fds, INT timeout);
+
+#endif // (_WIN32_WINNT >= 0x0600)
+
+ b) Create C:\MinGW\include\mstcpip.h and copy and paste the content from following link into it:
+
+ http://wine-unstable.sourcearchive.com/documentation/1.1.32/mstcpip_8h-source.html
+
+3. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html
+
+4. Install OpenSSL binaries. http://www.openssl.org/related/binaries.html
+
+ (**NOTE**: Preferably in the default location to make it easier for CMake to find them)
+
+ **NOTE2**:
+ Be sure that OPENSSL_CONF environment variable is defined and points at
+ <OpenSSL install location>\bin\openssl.cfg
+
+5. Generate the build files (default is Make files) using MSYS shell:
+
+ ```bash
+ $ cd /drive/path/to/src
+ $ mkdir build
+ $ cd build
+ $ cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=C:/MinGW ..
+ ```
+
+ (**NOTE**: The `build/`` directory can have any name and be located anywhere
+ on your filesystem, and that the argument `..` given to cmake is simply
+ the source directory of **libwebsockets** containing the [CMakeLists.txt](CMakeLists.txt)
+ project file. All examples in this file assumes you use "..")
+
+ **NOTE2**:
+ To generate build files allowing to create libwebsockets binaries with debug information
+ set the CMAKE_BUILD_TYPE flag to DEBUG:
+
+ ```bash
+ $ cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=C:/MinGW -DCMAKE_BUILD_TYPE=DEBUG ..
+ ```
+
+6. Finally you can build using the generated Makefile and get the results deployed into your MinGW installation:
+
+ ```bash
+ $ make
+ $ make install
+ ```
+
Setting compile options
-----------------------
**NOTE**: On windows use the .lib file extension for `LWS_CYASSL_LIBRARIES` instead.
-
Reproducing HTTP2.0 tests
-------------------------
Additional information on cross compilation with CMake:
http://www.vtk.org/Wiki/CMake_Cross_Compiling
-
Memory efficiency
-----------------
goto failed;
wsi->u.hdr.ah->c_port = context->http_proxy_port;
- n = send(wsi->sock, context->service_buffer, plen, MSG_NOSIGNAL);
+ n = send(wsi->sock, (char *)context->service_buffer, plen, MSG_NOSIGNAL);
if (n < 0) {
lwsl_debug("ERROR writing to proxy socket\n");
goto failed;
return 0;
}
- n = recv(wsi->sock, context->service_buffer,
+ n = recv(wsi->sock, (char *)context->service_buffer,
sizeof(context->service_buffer), 0);
if (n < 0) {
{
struct libwebsocket_context *context = NULL;
char *p;
-#ifdef _WIN32
- int i;
-#endif
int pid_daemon = get_daemonize_pid();
lwsl_notice("Initial logging level %d\n", log_level);
#include "lws_config.h"
#if defined(WIN32) || defined(_WIN32)
-
+#if (WINVER < 0x0501)
+#undef WINVER
+#undef _WIN32_WINNT
+#define WINVER 0x0501
+#define _WIN32_WINNT WINVER
+#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
int prev_events; // the previous event mask
};
-#ifdef _WIN32
+
+#if defined(_WIN32) && (_WIN32_WINNT < 0x0600)
struct libwebsocket_pollfd {
SOCKET fd;
SHORT events;
SHORT revents;
};
+WINSOCK_API_LINKAGE int WSAAPI WSAPoll(struct libwebsocket_pollfd fdArray[], ULONG fds, INT timeout);
#else
#define libwebsocket_pollfd pollfd
#endif
{
int n;
- n = recv(wsi->sock, buf, len, 0);
+ n = recv(wsi->sock, (char *)buf, len, 0);
if (n >= 0)
return n;
{
int n;
- n = send(wsi->sock, buf, len, MSG_NOSIGNAL);
+ n = send(wsi->sock, (char *)buf, len, MSG_NOSIGNAL);
if (n >= 0)
return n;
#endif
#if defined(WIN32) || defined(_WIN32)
+#if (WINVER < 0x0501)
+#undef WINVER
+#undef _WIN32_WINNT
+#define WINVER 0x0501
+#define _WIN32_WINNT WINVER
+#endif
#define LWS_NO_DAEMONIZE
#define LWS_ERRNO WSAGetLastError()
#define LWS_EAGAIN WSAEWOULDBLOCK
lws_latency_pre(context, wsi);
- n = recv(wsi->sock, context->service_buffer,
+ n = recv(wsi->sock, (char *)context->service_buffer,
sizeof(context->service_buffer), MSG_PEEK);
/*
#include <assert.h>
#include <signal.h>
+#include "../lib/libwebsockets.h"
+
#ifndef _WIN32
#include <syslog.h>
#include <sys/time.h>
#include <unistd.h>
+#else
+#include "gettimeofday.h"
+#include <process.h>
#endif
-#include "../lib/libwebsockets.h"
-
static volatile int force_exit = 0;
static int versa, state;
struct libwebsocket_context *context;
int opts = 0;
char interface_name[128] = "";
- const char *interface = NULL;
+ const char *_interface = NULL;
char ssl_cert[256] = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.pem";
char ssl_key[256] = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.key.pem";
-#ifndef WIN32
+#ifndef _WIN32
int syslog_options = LOG_PID | LOG_PERROR;
#endif
int client = 0;
#ifndef LWS_NO_DAEMONIZE
case 'D':
daemonize = 1;
-#ifndef WIN32
+#ifndef _WIN32
syslog_options &= ~LOG_PERROR;
#endif
break;
case 'i':
strncpy(interface_name, optarg, sizeof interface_name);
interface_name[(sizeof interface_name) - 1] = '\0';
- interface = interface_name;
+ _interface = interface_name;
break;
case '?':
case 'h':
#endif
#endif
-#ifdef WIN32
-#else
+#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);
-#endif
+
lwsl_notice("libwebsockets echo test - "
"(C) Copyright 2010-2015 Andy Green <andy@warmcat.com> - "
"licensed under LGPL2.1\n");
#endif
info.port = listen_port;
- info.iface = interface;
+ info.iface = _interface;
info.protocols = protocols;
#ifndef LWS_NO_EXTENSIONS
info.extensions = libwebsocket_get_internal_extensions();
libwebsocket_context_destroy(context);
lwsl_notice("libwebsockets-test-echo exited cleanly\n");
-#ifdef WIN32
-#else
+#ifndef _WIN32
closelog();
#endif
#include <signal.h>
#include <sys/types.h>
+#include "../lib/libwebsockets.h"
+
#ifndef _WIN32
#include <netdb.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <poll.h>
#include <unistd.h>
+#else
+#include "gettimeofday.h"
#endif
-#include "../lib/libwebsockets.h"
-
/*
* this is specified in the 04 standard, control frames can only have small
* payload length styles
{ NULL, 0, 0, 0 }
};
-#ifndef WIN32
+#ifndef _WIN32
static void
signal_handler(int sig, siginfo_t *si, void *v)
{
struct libwebsocket_context *context;
char protocol_name[256];
char ip[30];
-#ifndef WIN32
+#ifndef _WIN32
struct sigaction sa;
struct winsize w;
#endif
}
}
-#ifndef WIN32
+#ifndef _WIN32
if (isatty(STDOUT_FILENO))
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1)
if (w.ws_col > 0)
fprintf(stderr, "Websocket PING %s (%s) %d bytes of data.\n",
peer_name, ip, size);
-#ifndef WIN32
+#ifndef _WIN32
/* set the ^C handler */
sa.sa_sigaction = signal_handler;
sa.sa_flags = SA_SIGINFO;
#include <fcntl.h>
#include <assert.h>
+#include "../lib/libwebsockets.h"
+
#ifdef _WIN32
#include <io.h>
#ifdef EXTERNAL_POLL
#define poll WSAPoll
#endif
+#include "gettimeofday.h"
#else
#include <syslog.h>
#include <sys/time.h>
#include <unistd.h>
#endif
-#include "../lib/libwebsockets.h"
-
static int close_testing;
int max_poll_elements;
#ifdef EXTERNAL_POLL
-struct pollfd *pollfds;
+struct libwebsocket_pollfd *pollfds;
int *fd_lookup;
int count_pollfds;
#endif
p = buffer + LWS_SEND_BUFFER_PRE_PADDING;
end = p + sizeof(buffer) - LWS_SEND_BUFFER_PRE_PADDING;
-#ifdef WIN32
+#ifdef _WIN32
pss->fd = open(leaf_path, O_RDONLY | _O_BINARY);
#else
pss->fd = open(leaf_path, O_RDONLY);
int opts = 0;
char interface_name[128] = "";
const char *iface = NULL;
-#ifndef WIN32
+#ifndef _WIN32
int syslog_options = LOG_PID | LOG_PERROR;
#endif
unsigned int ms, oldms = 0;
#ifndef LWS_NO_DAEMONIZE
case 'D':
daemonize = 1;
- #ifndef WIN32
+ #ifndef _WIN32
syslog_options &= ~LOG_PERROR;
#endif
break;
signal(SIGINT, sighandler);
-#ifndef WIN32
+#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);
printf("Using resource path \"%s\"\n", resource_path);
#ifdef EXTERNAL_POLL
max_poll_elements = getdtablesize();
- pollfds = malloc(max_poll_elements * sizeof (struct pollfd));
+ pollfds = malloc(max_poll_elements * sizeof (struct libwebsocket_pollfd));
fd_lookup = malloc(max_poll_elements * sizeof (int));
if (pollfds == NULL || fd_lookup == NULL) {
lwsl_err("Out of memory pollfds=%d\n", max_poll_elements);
lwsl_notice("libwebsockets-test-server exited cleanly\n");
-#ifndef WIN32
+#ifndef _WIN32
closelog();
#endif
#include <time.h>\r
#include <windows.h> //I've omitted context line\r
\r
-#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)\r
- #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64\r
-#else\r
- #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL\r
-#endif\r
-\r
-#ifdef __MINGW32__\r
-#else\r
- #ifdef __MINGW64__\r
- #else\r
-struct timezone \r
-{\r
- int tz_minuteswest; /* minutes W of Greenwich */\r
- int tz_dsttime; /* type of dst correction */\r
-};\r
- #endif\r
-#endif\r
+#include "gettimeofday.h"\r
\r
int gettimeofday(struct timeval *tv, struct timezone *tz)\r
{\r
#ifndef _GET_TIME_OF_DAY_H
#define _GET_TIME_OF_DAY_H
-#ifdef __MINGW64__
-#else
-#ifdef __MINGW32__
-#else
-#include < time.h >
-#endif
-#endif
-
-#include <windows.h> //I've omitted context line.
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else
# endif\r
#endif\r
\r
-#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)\r
+#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) && !defined(_WIN32)\r
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))\r
#else\r
# define ZLIB_INTERNAL\r
#ifndef ZUTIL_H\r
#define ZUTIL_H\r
\r
-#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)\r
+#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) && !defined(_WIN32)\r
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))\r
#else\r
# define ZLIB_INTERNAL\r