mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
windows: clean LWS_WITH_MINIMAL_EXAMPLES warnings
Fix pthreads detection in the minimal examples and add it where needed. Fix unistd.h include to be conditional on not WIN32 With this, -DLWS_WITH_MINIMAL_EXAMPLES=1 is happy and warning-free on windows.
This commit is contained in:
parent
1a8833dcfd
commit
954fcf2bc3
26 changed files with 67 additions and 35 deletions
|
@ -346,7 +346,7 @@ int main(int argc, const char **argv)
|
|||
|
||||
lws_struct_json_init_parse(&ctx, NULL, &a);
|
||||
n = (int)(signed char)lejp_parse(&ctx, (uint8_t *)json_tests[m],
|
||||
strlen(json_tests[m]));
|
||||
(int)strlen(json_tests[m]));
|
||||
if (n < 0) {
|
||||
lwsl_err("%s: notification JSON decode failed '%s'\n",
|
||||
__func__, lejp_error_to_string(n));
|
||||
|
|
|
@ -11,7 +11,8 @@ MACRO(require_pthreads result)
|
|||
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
|
||||
if (NOT LWS_HAVE_PTHREAD_H)
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(result 0)
|
||||
set(${result} 0)
|
||||
message("${SAMP}: skipping as no pthreads")
|
||||
else()
|
||||
message(FATAL_ERROR "threading support requires pthreads")
|
||||
endif()
|
||||
|
|
|
@ -72,7 +72,7 @@ require_lws_config(LWS_ROLE_WS 1 requirements)
|
|||
require_lws_config(LWS_WITH_SERVER 1 requirements)
|
||||
require_lws_config(LWS_WITH_HTTP_BASIC_AUTH 1 requirements)
|
||||
|
||||
if (requirements)
|
||||
if (requirements AND UNIX)
|
||||
add_executable(${SAMP} ${SRCS})
|
||||
|
||||
if (LWS_PLUGINS_DIR)
|
||||
|
|
|
@ -10,7 +10,8 @@ MACRO(require_pthreads result)
|
|||
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
|
||||
if (NOT LWS_HAVE_PTHREAD_H)
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(result 0)
|
||||
set(${result} 0)
|
||||
message("${SAMP}: skipping as no pthreads")
|
||||
else()
|
||||
message(FATAL_ERROR "threading support requires pthreads")
|
||||
endif()
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
#include <libwebsockets.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#if !defined(WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
|
|
@ -10,7 +10,8 @@ MACRO(require_pthreads result)
|
|||
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
|
||||
if (NOT LWS_HAVE_PTHREAD_H)
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(result 0)
|
||||
set(${result} 0)
|
||||
message("${SAMP}: skipping as no pthreads")
|
||||
else()
|
||||
message(FATAL_ERROR "threading support requires pthreads")
|
||||
endif()
|
||||
|
|
|
@ -10,7 +10,8 @@ MACRO(require_pthreads result)
|
|||
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
|
||||
if (NOT LWS_HAVE_PTHREAD_H)
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(result 0)
|
||||
set(${result} 0)
|
||||
message("${SAMP}: skipping as no pthreads")
|
||||
else()
|
||||
message(FATAL_ERROR "threading support requires pthreads")
|
||||
endif()
|
||||
|
|
|
@ -5,6 +5,18 @@ include(CheckCSourceCompiles)
|
|||
set(SAMP lws-minimal-http-server-sse)
|
||||
set(SRCS minimal-http-server-sse.c)
|
||||
|
||||
MACRO(require_pthreads result)
|
||||
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
|
||||
if (NOT LWS_HAVE_PTHREAD_H)
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(${result} 0)
|
||||
message("${SAMP}: skipping as no pthreads")
|
||||
else()
|
||||
message(FATAL_ERROR "threading support requires pthreads")
|
||||
endif()
|
||||
endif()
|
||||
ENDMACRO()
|
||||
|
||||
# If we are being built as part of lws, confirm current build config supports
|
||||
# reqconfig, else skip building ourselves.
|
||||
#
|
||||
|
@ -64,6 +76,7 @@ MACRO(require_lws_config reqconfig _val result)
|
|||
ENDMACRO()
|
||||
|
||||
set(requirements 1)
|
||||
require_pthreads(requirements)
|
||||
require_lws_config(LWS_ROLE_H1 1 requirements)
|
||||
require_lws_config(LWS_WITH_SERVER 1 requirements)
|
||||
|
||||
|
|
|
@ -429,9 +429,9 @@ int main(int argc, const char **argv)
|
|||
info.mounts = &mount;
|
||||
info.error_document_404 = "/404.html";
|
||||
info.server_ssl_cert_mem = cert_pem;
|
||||
info.server_ssl_cert_mem_len = strlen(cert_pem);
|
||||
info.server_ssl_cert_mem_len = (unsigned int)strlen(cert_pem);
|
||||
info.server_ssl_private_key_mem = key_pem;
|
||||
info.server_ssl_private_key_mem_len = strlen(key_pem);
|
||||
info.server_ssl_private_key_mem_len = (unsigned int)strlen(key_pem);
|
||||
info.vhost_name = "first";
|
||||
|
||||
if (!lws_create_vhost(context, &info)) {
|
||||
|
@ -443,9 +443,9 @@ int main(int argc, const char **argv)
|
|||
info.mounts = &mount;
|
||||
info.error_document_404 = "/404.html";
|
||||
info.server_ssl_cert_mem = cert_der;
|
||||
info.server_ssl_cert_mem_len = sizeof(cert_der);
|
||||
info.server_ssl_cert_mem_len = (unsigned int)sizeof(cert_der);
|
||||
info.server_ssl_private_key_mem = key_der;
|
||||
info.server_ssl_private_key_mem_len = sizeof(key_der);
|
||||
info.server_ssl_private_key_mem_len = (unsigned int)sizeof(key_der);
|
||||
info.vhost_name = "second";
|
||||
|
||||
if (!lws_create_vhost(context, &info)) {
|
||||
|
|
|
@ -31,7 +31,9 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#if !defined(WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
static int
|
||||
|
|
|
@ -28,7 +28,9 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#if !defined(WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
static uint8_t sendbuf[4096];
|
||||
|
@ -40,7 +42,7 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
void *user, void *in, size_t len)
|
||||
{
|
||||
ssize_t n;
|
||||
int fd;
|
||||
lws_sockfd_type fd;
|
||||
|
||||
switch (reason) {
|
||||
|
||||
|
@ -102,7 +104,7 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
#if defined(WIN32)
|
||||
(const char *)
|
||||
#endif
|
||||
sendbuf, sendlen, 0, &udp.sa, udp.salen);
|
||||
sendbuf, sendlen, 0, &udp.sa, (socklen_t)udp.salen);
|
||||
if (n < (ssize_t)len)
|
||||
lwsl_notice("%s: send returned %d\n", __func__, (int)n);
|
||||
break;
|
||||
|
|
|
@ -63,7 +63,7 @@ callback_raw_echo(struct lws *wsi, enum lws_callback_reasons reason, void *user,
|
|||
if (len > sizeof(pss->buf))
|
||||
len = sizeof(pss->buf);
|
||||
memcpy(pss->buf, in, len);
|
||||
pss->len = len;
|
||||
pss->len = (int)len;
|
||||
lws_callback_on_writable(wsi);
|
||||
break;
|
||||
|
||||
|
|
|
@ -26,7 +26,9 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#if !defined(WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
static struct lws *raw_wsi, *stdin_wsi;
|
||||
|
|
|
@ -66,7 +66,7 @@ ENDMACRO()
|
|||
set(requirements 1)
|
||||
require_lws_config(LWS_WITH_SERVER 1 requirements)
|
||||
|
||||
if (requirements)
|
||||
if (requirements AND UNIX)
|
||||
add_executable(${SAMP} ${SRCS})
|
||||
|
||||
if (websockets_shared)
|
||||
|
|
|
@ -75,7 +75,7 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
|
||||
case LWS_CALLBACK_RAW_RX:
|
||||
lwsl_user("LWS_CALLBACK_RAW_RX: %d\n", (int)len);
|
||||
vhd->len = len;
|
||||
vhd->len = (int)len;
|
||||
if (vhd->len > (int)sizeof(vhd->buf))
|
||||
vhd->len = sizeof(vhd->buf);
|
||||
memcpy(vhd->buf, in, vhd->len);
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#if !defined(WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ MACRO(require_pthreads result)
|
|||
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
|
||||
if (NOT LWS_HAVE_PTHREAD_H)
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(result 0)
|
||||
set(${result} 0)
|
||||
message("${SAMP}: skipping as no pthreads")
|
||||
else()
|
||||
message(FATAL_ERROR "threading support requires pthreads")
|
||||
endif()
|
||||
|
|
|
@ -181,14 +181,14 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
if (s > (size_t)n)
|
||||
s = n;
|
||||
memcpy(p, &redundant_string[m], s);
|
||||
pss->position_tx += s;
|
||||
pss->position_tx += (int)s;
|
||||
p += s;
|
||||
n -= s;
|
||||
n -= (int)s;
|
||||
}
|
||||
} else {
|
||||
pss->position_tx += n;
|
||||
while (n--)
|
||||
*p++ = rng(&pss->rng_tx);
|
||||
*p++ = (uint8_t)rng(&pss->rng_tx);
|
||||
}
|
||||
|
||||
n = lws_ptr_diff(p, start);
|
||||
|
@ -227,13 +227,13 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
lwsl_user("echo'd data doesn't match\n");
|
||||
return -1;
|
||||
}
|
||||
pss->position_rx += s;
|
||||
pss->position_rx += (int)s;
|
||||
in = ((unsigned char *)in) + s;
|
||||
len -= s;
|
||||
}
|
||||
} else {
|
||||
p = (uint8_t *)in;
|
||||
pss->position_rx += len;
|
||||
pss->position_rx += (int)len;
|
||||
while (len--)
|
||||
if (*p++ != (uint8_t)rng(&pss->rng_rx)) {
|
||||
lwsl_user("echo'd data doesn't match\n");
|
||||
|
|
|
@ -10,7 +10,8 @@ MACRO(require_pthreads result)
|
|||
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
|
||||
if (NOT LWS_HAVE_PTHREAD_H)
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(result 0)
|
||||
set(${result} 0)
|
||||
message("${SAMP}: skipping as no pthreads")
|
||||
else()
|
||||
message(FATAL_ERROR "threading support requires pthreads")
|
||||
endif()
|
||||
|
|
|
@ -10,7 +10,8 @@ MACRO(require_pthreads result)
|
|||
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
|
||||
if (NOT LWS_HAVE_PTHREAD_H)
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(result 0)
|
||||
set(${result} 0)
|
||||
message("${SAMP}: skipping as no pthreads")
|
||||
else()
|
||||
message(FATAL_ERROR "threading support requires pthreads")
|
||||
endif()
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include <libwebsockets.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
|
||||
/*
|
||||
* This represents your object that "contains" the client connection and has
|
||||
|
|
|
@ -147,14 +147,14 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
if (s > (size_t)n)
|
||||
s = n;
|
||||
memcpy(p, &redundant_string[m], s);
|
||||
pss->position_tx += s;
|
||||
pss->position_tx += (int)s;
|
||||
p += s;
|
||||
n -= s;
|
||||
n -= (int)s;
|
||||
}
|
||||
} else {
|
||||
pss->position_tx += n;
|
||||
while (n--)
|
||||
*p++ = rng(&pss->rng_tx);
|
||||
*p++ = (uint8_t)rng(&pss->rng_tx);
|
||||
}
|
||||
|
||||
n = lws_ptr_diff(p, start);
|
||||
|
@ -172,7 +172,7 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
lwsl_user("LWS_CALLBACK_RECEIVE: %4d (pss->pos=%d, rpp %5d, last %d)\n",
|
||||
(int)len, (int)pss->position_rx, (int)lws_remaining_packet_payload(wsi),
|
||||
lws_is_final_fragment(wsi));
|
||||
olen = len;
|
||||
olen = (int)len;
|
||||
|
||||
if (*vhd->options & 1) {
|
||||
while (len) {
|
||||
|
@ -185,13 +185,13 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
lwsl_user("echo'd data doesn't match\n");
|
||||
return -1;
|
||||
}
|
||||
pss->position_rx += s;
|
||||
pss->position_rx += (int)s;
|
||||
in = ((char *)in) + s;
|
||||
len -= s;
|
||||
}
|
||||
} else {
|
||||
p = (uint8_t *)in;
|
||||
pss->position_rx += len;
|
||||
pss->position_rx += (int)len;
|
||||
while (len--) {
|
||||
if (*p++ != (uint8_t)rng(&pss->rng_rx)) {
|
||||
lwsl_user("echo'd data doesn't match: 0x%02X 0x%02X (%d)\n",
|
||||
|
|
|
@ -55,7 +55,7 @@ cull_lagging_clients(struct per_vhost_data__minimal *vhd)
|
|||
{
|
||||
uint32_t oldest_tail = lws_ring_get_oldest_tail(vhd->ring);
|
||||
struct per_session_data__minimal *old_pss = NULL;
|
||||
int most = 0, before = lws_ring_get_count_waiting_elements(vhd->ring,
|
||||
int most = 0, before = (int)lws_ring_get_count_waiting_elements(vhd->ring,
|
||||
&oldest_tail), m;
|
||||
|
||||
/*
|
||||
|
@ -111,7 +111,7 @@ cull_lagging_clients(struct per_vhost_data__minimal *vhd)
|
|||
* what is the largest number of pending ring elements
|
||||
* for any survivor.
|
||||
*/
|
||||
m = lws_ring_get_count_waiting_elements(vhd->ring,
|
||||
m = (int)lws_ring_get_count_waiting_elements(vhd->ring,
|
||||
&((*ppss)->tail));
|
||||
if (m > most)
|
||||
most = m;
|
||||
|
|
|
@ -10,7 +10,8 @@ MACRO(require_pthreads result)
|
|||
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
|
||||
if (NOT LWS_HAVE_PTHREAD_H)
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(result 0)
|
||||
set(${result} 0)
|
||||
message("${SAMP}: skipping as no pthreads")
|
||||
else()
|
||||
message(FATAL_ERROR "threading support requires pthreads")
|
||||
endif()
|
||||
|
|
|
@ -10,7 +10,8 @@ MACRO(require_pthreads result)
|
|||
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
|
||||
if (NOT LWS_HAVE_PTHREAD_H)
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(result 0)
|
||||
set(${result} 0)
|
||||
message("${SAMP}: skipping as no pthreads")
|
||||
else()
|
||||
message(FATAL_ERROR "threading support requires pthreads")
|
||||
endif()
|
||||
|
|
|
@ -10,7 +10,8 @@ MACRO(require_pthreads result)
|
|||
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
|
||||
if (NOT LWS_HAVE_PTHREAD_H)
|
||||
if (LWS_WITH_MINIMAL_EXAMPLES)
|
||||
set(result 0)
|
||||
set(${result} 0)
|
||||
message("${SAMP}: skipping as no pthreads")
|
||||
else()
|
||||
message(FATAL_ERROR "threading support requires pthreads")
|
||||
endif()
|
||||
|
|
Loading…
Add table
Reference in a new issue