diff --git a/.travis.yml b/.travis.yml index d833f8ad8641e00b86d00c9da708fbdf18a76903..e89f39db280f8298dbb3b343b4278fe08fcde41b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,11 +4,11 @@ env: global: - secure: "KhAdQ9ja+LBObWNQTYO7Df5J4DyOih6S+eerDMu8UPSO+CoWV2pWoQzbOfocjyOscGOwC+2PrrHDNZyGfqkCLDXg1BxynXPCFerHC1yc2IajvKpGXmAAygNIvp4KACDfGv/dkXrViqIzr/CdcNaU4vIMHSVb5xkeLi0W1dPnQOI=" matrix: - - LWS_METHOD=lwsws CMAKE_ARGS="-DLWS_WITH_LWSWS=ON -DLWS_WITH_HTTP2=1 -DLWS_WITH_ACME=1" - - LWS_METHOD=default - - LWS_METHOD=noserver CMAKE_ARGS="-DLWS_WITHOUT_SERVER=ON" - - LWS_METHOD=noclient CMAKE_ARGS="-DLWS_WITHOUT_CLIENT=ON" - - LWS_METHOD=noext CMAKE_ARGS="-DLWS_WITHOUT_EXTENSIONS=ON" + - LWS_METHOD=lwsws CMAKE_ARGS="-DLWS_WITH_LWSWS=ON -DLWS_WITH_HTTP2=1 -DLWS_WITH_ACME=1 -DLWS_WITH_MINIMAL_EXAMPLES=1" + - LWS_METHOD=default CMAKE_ARGS="-DLWS_WITH_MINIMAL_EXAMPLES=1" + - LWS_METHOD=noserver CMAKE_ARGS="-DLWS_WITHOUT_SERVER=ON -DLWS_WITH_MINIMAL_EXAMPLES=1" + - LWS_METHOD=noclient CMAKE_ARGS="-DLWS_WITHOUT_CLIENT=ON -DLWS_WITH_MINIMAL_EXAMPLES=1" + - LWS_METHOD=noext CMAKE_ARGS="-DLWS_WITHOUT_EXTENSIONS=ON -DLWS_WITH_MINIMAL_EXAMPLES=1" - LWS_METHOD=libev CMAKE_ARGS="-DLWS_WITH_LIBEV=ON" - LWS_METHOD=noipv6 CMAKE_ARGS="-DLWS_IPV6=OFF" - LWS_METHOD=nossl CMAKE_ARGS="-DLWS_WITH_SSL=OFF" diff --git a/CMakeLists.txt b/CMakeLists.txt index 6648ac1f2669d3b951018285af0e501c6f77b22d..db2ea7809a664459ced58b644dcaa3ff08a33f1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,6 +101,7 @@ option(LWS_WITH_SELFTESTS "Selftests run at context creation" OFF) option(LWS_WITH_GCOV "Build with gcc gcov coverage instrumentation" OFF) option(LWS_WITH_EXPORT_LWSTARGETS "Export libwebsockets CMake targets. Disable if they conflict with an outer cmake project." ON) option(LWS_REPRODUCIBLE "Build libwebsockets reproducible. It removes the build user and hostname from the build" ON) +option(LWS_WITH_MINIMAL_EXAMPLES "Also build the normally standalone minimal examples, for QA" OFF) # # End of user settings # @@ -123,7 +124,6 @@ if(LWS_WITH_DISTRO_RECOMMENDED) set(LWS_WITHOUT_EXTENSIONS 0) endif() - if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type") endif() @@ -196,6 +196,10 @@ if(GIT_EXECUTABLE) message("Git commit hash: ${LWS_BUILD_HASH}") endif() +if (LWS_WITH_HTTP2 AND LWS_WITHOUT_SERVER) + message(FATAL_ERROR "HTTP2 can only be used with server at the moment") +endif() + if (LWS_WITH_LWSWS) message(STATUS "LWS_WITH_LWSWS --> Enabling LWS_WITH_PLUGINS and LWS_WITH_LIBUV") set(LWS_WITH_PLUGINS 1) @@ -814,7 +818,7 @@ if (NOT LWS_WITHOUT_BUILTIN_SHA1) lib/misc/sha-1.c) endif() -if (LWS_WITH_HTTP2) +if (LWS_WITH_HTTP2 AND NOT LWS_WITHOUT_SERVER) list(APPEND SOURCES lib/http2/http2.c lib/http2/hpack.c @@ -1532,7 +1536,7 @@ if (NOT LWS_WITHOUT_TESTAPPS) "" "") endif() - if (UNIX AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND LWS_HAVE_PTHREAD_H) + if (UNIX AND NOT LWS_WITHOUT_SERVER AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND LWS_HAVE_PTHREAD_H) create_test_app(test-server-pthreads "test-apps/test-server-pthreads.c" "test-apps/test-server-http.c" @@ -1662,20 +1666,20 @@ if (NOT LWS_WITHOUT_TESTAPPS) # # test-fraggle # - if (NOT LWS_WITHOUT_TEST_FRAGGLE) + if (NOT LWS_WITHOUT_TEST_FRAGGLE AND NOT LWS_WITHOUT_SERVER) create_test_app(test-fraggle "test-apps/test-fraggle.c" "" "" "" "" "") endif() # # test-ping # - if (NOT LWS_WITHOUT_TEST_PING) + if (NOT LWS_WITHOUT_TEST_PING AND NOT LWS_WITHOUT_SERVER AND NOT LWS_WITHOUT_CLIENT) create_test_app(test-ping "test-apps/test-ping.c" "" "" "" "" "") endif() # # test-echo # - if (NOT LWS_WITHOUT_TEST_ECHO) + if (NOT LWS_WITHOUT_TEST_ECHO AND NOT LWS_WITHOUT_SERVER AND NOT LWS_WITHOUT_CLIENT) create_test_app(test-echo "test-apps/test-echo.c" "" "" "" "" "") endif() @@ -2157,5 +2161,32 @@ if (LWS_WITH_SHARED) set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library") endif() +if (LWS_WITH_MINIMAL_EXAMPLES) + MACRO(SUBDIRLIST result curdir) + FILE(GLOB children RELATIVE ${curdir} ${curdir}/*) + SET(dirlist "") + + FOREACH(child ${children}) + IF(IS_DIRECTORY ${curdir}/${child}) + LIST(APPEND dirlist ${child}) + ENDIF() + ENDFOREACH() + + SET(${result} ${dirlist}) + ENDMACRO() + + SUBDIRLIST(SUBDIRS "${PROJECT_SOURCE_DIR}/minimal-examples") + FOREACH(subdir ${SUBDIRS}) + + SUBDIRLIST(SUBDIRS2 "${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}") + FOREACH(subdir2 ${SUBDIRS2}) + if (EXISTS "${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}/CMakeLists.txt") + message("Processing ${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}") + add_subdirectory("${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}") + endif() + ENDFOREACH() + ENDFOREACH() +ENDIF() + # This must always be last! include(CPack) diff --git a/cmake/lws_config.h.in b/cmake/lws_config.h.in index a77fa173b821daf2a67f18672cea686098fb8ecc..64904e8e65f59e3679c0394c19feaeeb6f21a5e4 100644 --- a/cmake/lws_config.h.in +++ b/cmake/lws_config.h.in @@ -47,6 +47,11 @@ /* Turn off websocket extensions */ #cmakedefine LWS_NO_EXTENSIONS +#cmakedefine LWS_WITHOUT_EXTENSIONS + +/* notice if client or server gone */ +#cmakedefine LWS_WITHOUT_SERVER +#cmakedefine LWS_WITHOUT_CLIENT /* Enable libev io loop */ #cmakedefine LWS_WITH_LIBEV diff --git a/minimal-examples/README.md b/minimal-examples/README.md index 003a80083c034e582ef8e9a6ffb1c92635a81690..e4fc7515f7f5b5642456bd90becaaefe0016b017 100644 --- a/minimal-examples/README.md +++ b/minimal-examples/README.md @@ -8,9 +8,11 @@ client-server|Minimal examples providing client and server connections simultane ## FAQ -### What should I look at first +### Getting started -Build and install lws itself first, these examples all want to link to it. Then +Build and install lws itself first (note that after installing lws on \*nix, you need to run `ldconfig` one time so the OS can learn about the new library. Lws installs in `/usr/local` by default, Debian / Ubuntu ldconfig knows to look there already, but Fedora / CentOS need you to add the line `/usr/local/lib` to `/etc/ld.so.conf` and run ldconfig) + +Then start with the simplest: `http-server/minimal-http-server` @@ -37,7 +39,7 @@ You will notice a lot of the main C code is the same boilerplate repeated for each example. The actual interesting part is in the protocol callback only. -Lws provides a generic lightweight server app called 'lwsws' that +Lws provides (-DLWS_WITH_LWSWS=1) a generic lightweight server app called 'lwsws' that can be configured by JSON. Combined with your protocol as a plugin, it means you don't actually have to make a special server "app" part, you can just use lwsws and pass per-vhost configuration @@ -46,9 +48,14 @@ an existing app you are bolting lws on to, then you don't care about this for that particular case). Because lwsws has no dependency on whatever your plugin does, it -can mix and match different protocols without needing any code +can mix and match different protocols randomly without needing any code changes. It reduces the size of the task to just writing the -code you care about in your protocol handler. +code you care about in your protocol handler, and nothing else to write +or maintain. + +Lwsws supports advanced features like reload, where it starts a new server +instance with changed config or different plugins, while keeping the old +instance around until the last connection to it closes. ### I get why there is a pss, but why is there a vhd? @@ -67,7 +74,8 @@ provides a different vhd specific to the protocol instance on that vhost. For example many of the samples keep a linked-list head to a list of live pss in the vhd... that means it's cleanly a list of pss opened **on that vhost**. If another vhost has the protocol -enabled, connections to that will point to a different vhd. +enabled, connections to that will point to a different vhd, and the +linked-list head on that vhd will only list connections to his vhost. The example "ws-server/minimal-ws-server-threads" demonstrates how to deliver external configuration data to a specific vhost + protocol diff --git a/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt b/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt index 3ec2949ea616eb28551659dda43f78a64b0e7f33..006d260e23adf5632c7ceabbd96b78d0c15a8422 100644 --- a/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt +++ b/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt @@ -1,11 +1,77 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-proxy) set(SRCS minimal-ws-proxy.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c b/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c index 08ab0584e697f80fc923b9e88e383c9637be6924..983c526f069f87781a73baee1896ac69da370918 100644 --- a/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c +++ b/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c @@ -89,7 +89,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, lws_get_protocol(wsi)); const struct msg *pmsg; struct msg amsg; - int n, m; + int m; switch (reason) { @@ -142,7 +142,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len, LWS_WRITE_TEXT); if (m < (int)pmsg->len) { - lwsl_err("ERROR %d writing to di socket\n", n); + lwsl_err("ERROR %d writing to ws socket\n", m); return -1; } @@ -181,8 +181,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, if (!vhd->pss_list) break; - n = (int)lws_ring_get_count_free_elements(vhd->ring); - if (!n) { + if (!lws_ring_get_count_free_elements(vhd->ring)) { lwsl_user("dropping!\n"); break; } @@ -210,7 +209,6 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, ppss, vhd->pss_list) { lws_callback_on_writable((*ppss)->wsi); } lws_end_foreach_llp(ppss, pss_list); - break; case LWS_CALLBACK_CLIENT_CLOSED: diff --git a/minimal-examples/http-client/minimal-http-client/CMakeLists.txt b/minimal-examples/http-client/minimal-http-client/CMakeLists.txt index 5d6d26495351cca4484f9a8c57349e65b73804a8..511362ed97c05bb38406cfbd6ffd8cba1bedd277 100644 --- a/minimal-examples/http-client/minimal-http-client/CMakeLists.txt +++ b/minimal-examples/http-client/minimal-http-client/CMakeLists.txt @@ -1,12 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-http-client) set(SRCS minimal-http-client.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/http-server/minimal-http-server-libuv/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-libuv/CMakeLists.txt index 8168b245bbea044ce82182ff53266e83bf1a7a86..3a2a0e5adee668687f07f638eae9d22f4e268649 100644 --- a/minimal-examples/http-server/minimal-http-server-libuv/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server-libuv/CMakeLists.txt @@ -4,16 +4,74 @@ include(CheckSymbolExists) set(SAMP lws-minimal-http-server-libuv) set(SRCS minimal-http-server.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -CHECK_SYMBOL_EXISTS(LWS_WITH_LIBUV libwebsockets.h HAS_LIBUV) -if (HAS_LIBUV) -else() - message(FATAL_ERROR "lws must have been built with LWS_WITH_LIBUV") -endif() + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITH_LIBUV 1 requirements) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt index 5077704af54139a4bdc226238a49caa498e2ffa7..5684ff2fac24f5cdba8c09bfdc30c0da5cbfb5f6 100644 --- a/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt @@ -1,12 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-http-server-multivhost) set(SRCS minimal-http-server.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt index 8dcdc847aeb1ddc8f42c8a7490f73f3cc88fc615..59f49b751c8589860037c87e79f905f79c625df9 100644 --- a/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt @@ -1,18 +1,89 @@ cmake_minimum_required(VERSION 2.8) include(CheckIncludeFile) +include(CheckSymbolExists) set(SAMP lws-minimal-http-server-smp) set(SRCS minimal-http-server-smp.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +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) + else() + message(FATAL_ERROR "threading support requires pthreads") + endif() + endif() +ENDMACRO() -CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) -if (NOT LWS_HAVE_PTHREAD_H) - message(FATAL_ERROR "smp support requires pthreads") -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets -lpthread) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_pthreads(requirements) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared pthread) + add_dependencies(${SAMP} websockets_shared pthread) + else() + target_link_libraries(${SAMP} websockets pthread) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c b/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c index 86bbb1ad5901091b1b1b8ef50489eda215af92bc..417afb6f813e099f8e6f28e5fa0ba9df3a6ed863 100644 --- a/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c +++ b/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c @@ -21,6 +21,7 @@ #include <libwebsockets.h> #include <string.h> #include <signal.h> +#include <pthread.h> #define COUNT_THREADS 8 diff --git a/minimal-examples/http-server/minimal-http-server/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server/CMakeLists.txt index f054a4e15881c1d29a333ad7be4dac0dc811eecd..457e817a4cda9145b1fb482a8ec12534c5d3bc4e 100644 --- a/minimal-examples/http-server/minimal-http-server/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server/CMakeLists.txt @@ -1,12 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-http-server) set(SRCS minimal-http-server.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt b/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt index 659779b6c144d1bd8030348cc093604a95f2141e..22f690143ab239cd878bedd5facc2be77365b4a6 100644 --- a/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt +++ b/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt @@ -1,12 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-client-rx) set(SRCS minimal-ws-client.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt b/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt index 69d5be4d399502600cdb82556b09210d060b63f9..156d7c35032e7fe559867f6b2983c0133705f173 100644 --- a/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt +++ b/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt @@ -1,18 +1,88 @@ cmake_minimum_required(VERSION 2.8) include(CheckIncludeFile) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-client-tx) set(SRCS minimal-ws-client.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +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) + 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. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) -if (NOT LWS_HAVE_PTHREAD_H) - message(FATAL_ERROR "threading support requires pthreads") -endif() + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets -pthread) + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_pthreads(requirements) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared pthread) + add_dependencies(${SAMP} websockets_shared pthread) + else() + target_link_libraries(${SAMP} websockets pthread) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c b/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c index b5540fb1eb44ecb83701bb07c20c5d432a4b4b89..4a925416415e14b90150c88eab089261987365c5 100644 --- a/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c +++ b/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c @@ -21,6 +21,7 @@ #include <libwebsockets.h> #include <string.h> #include <signal.h> +#include <pthread.h> static int interrupted; @@ -217,7 +218,7 @@ init_fail: LWS_WRITE_TEXT); if (m < (int)pmsg->len) { pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock */ - lwsl_err("ERROR %d writing to di socket\n", n); + lwsl_err("ERROR %d writing to ws socket\n", m); return -1; } diff --git a/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt index fc84b8715db8a9d1346db44ba60346dd11f5e939..8ad44309fdfc3ca12d1865f8095981ac8a052c4c 100644 --- a/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt @@ -1,11 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-broker) set(SRCS minimal-ws-broker.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c index b53184fbd38084c45e8c1d909fb4b8272f528a4e..b2efc6cbee66f53504bcb5b7da2ecfd8ed37aeb3 100644 --- a/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c @@ -136,7 +136,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len, LWS_WRITE_TEXT); if (m < (int)pmsg->len) { - lwsl_err("ERROR %d writing to di socket\n", n); + lwsl_err("ERROR %d writing to ws socket\n", m); return -1; } diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt index f872dd90c69f8f39aab8a2e2c68d29d76e6f6fc0..36af4b78d09b77db518cf36fa37495b1dd9d0d78 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt @@ -1,20 +1,77 @@ cmake_minimum_required(VERSION 2.8.9) -include(CheckFunctionExists) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-server-pmd-bulk) set(SRCS minimal-ws-server-pmd-bulk.c) -set(CMAKE_REQUIRED_LIBRARIES websockets) +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -CHECK_FUNCTION_EXISTS(lws_extension_callback_pm_deflate HAVE_PMD) -if (HAVE_PMD) -else() - message(FATAL_ERROR "LWS need to have been built for extensions") -endif() + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITHOUT_EXTENSIONS 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt index 72ffa07c4aaf4ea0022676d70e7c10e3dbf6c9f3..8b9721b11de8b3dd1260f59aac36c2597184c448 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt @@ -1,20 +1,77 @@ cmake_minimum_required(VERSION 2.8.9) -include(CheckFunctionExists) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-server-pmd) set(SRCS minimal-ws-server-pmd.c) -set(CMAKE_REQUIRED_LIBRARIES websockets) +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -CHECK_FUNCTION_EXISTS(lws_extension_callback_pm_deflate HAVE_PMD) -if (HAVE_PMD) -else() - message(FATAL_ERROR "LWS needs to have been built for extensions") -endif() + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITHOUT_EXTENSIONS 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c index 70ccefe636012200d385cb3cbd87b0e4d976059c..b9ec3305f9a23f2a91780c4ac9128c4c98cca51a 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c @@ -69,7 +69,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, (struct per_vhost_data__minimal *) lws_protocol_vh_priv_get(lws_get_vhost(wsi), lws_get_protocol(wsi)); - int n, m; + int m; switch (reason) { case LWS_CALLBACK_PROTOCOL_INIT: @@ -111,7 +111,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, m = lws_write(wsi, vhd->amsg.payload + LWS_PRE, vhd->amsg.len, LWS_WRITE_TEXT); if (m < (int)vhd->amsg.len) { - lwsl_err("ERROR %d writing to di socket\n", n); + lwsl_err("ERROR %d writing to ws socket\n", m); return -1; } diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt index 3bfdc5ff7c4996a3abc9ed7712acbbd042f976c7..04e9d5bd2f6d34515728847be8ae5f5c54678fec 100644 --- a/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt @@ -1,11 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-server-ring) set(SRCS minimal-ws-server.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c index f61c1414d1fb1e9574fd87d15a55da1df66bc064..cdf1216e648b609a4bd4eeca85a33920a46a00e4 100644 --- a/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c @@ -112,7 +112,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len, LWS_WRITE_TEXT); if (m < (int)pmsg->len) { - lwsl_err("ERROR %d writing to di socket\n", n); + lwsl_err("ERROR %d writing to ws socket\n", m); return -1; } diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt index 0849c579da4e39669e07c084aff146f8f526a428..8b147749387722480b2c322149c63eb2d64b27bc 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt @@ -1,17 +1,89 @@ cmake_minimum_required(VERSION 2.8) include(CheckIncludeFile) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-server-threads) set(SRCS minimal-ws-server.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +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) + else() + message(FATAL_ERROR "threading support requires pthreads") + endif() + endif() +ENDMACRO() -CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) -if (NOT LWS_HAVE_PTHREAD_H) - message(FATAL_ERROR "threading support requires pthreads") -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets -pthread) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_pthreads(requirements) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c b/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c index 90773454ff6762f6a0e70ced2d7d0856a047f7c0..c4f365744ab655ace9cda9994b3b675fb670bdf3 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c +++ b/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c @@ -21,6 +21,7 @@ #include <libwebsockets.h> #include <string.h> #include <signal.h> +#include <pthread.h> #define LWS_PLUGIN_STATIC #include "protocol_lws_minimal.c" diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c index 6bfddeda3187e5640faa09ff66d77b5eed0d7291..121296291a6b2190934edc94237c479d7cea6f7a 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c @@ -228,7 +228,7 @@ init_fail: LWS_WRITE_TEXT); if (m < (int)pmsg->len) { pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock ------- */ - lwsl_err("ERROR %d writing to di socket\n", n); + lwsl_err("ERROR %d writing to ws socket\n", m); return -1; } diff --git a/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt index 8dd86a0496a1cc8211a1c4982cc2ee448843554b..6ec72fe965f853cf5059f15a332f59f4ff98adec 100644 --- a/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt @@ -1,11 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-server) set(SRCS minimal-ws-server.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c index 63200a932469bbce5a82c229950f3bda95dbf8d1..bc161a87d770072a0933a5249d7ecde88743aa03 100644 --- a/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c @@ -69,7 +69,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, (struct per_vhost_data__minimal *) lws_protocol_vh_priv_get(lws_get_vhost(wsi), lws_get_protocol(wsi)); - int n, m; + int m; switch (reason) { case LWS_CALLBACK_PROTOCOL_INIT: @@ -111,7 +111,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, m = lws_write(wsi, vhd->amsg.payload + LWS_PRE, vhd->amsg.len, LWS_WRITE_TEXT); if (m < (int)vhd->amsg.len) { - lwsl_err("ERROR %d writing to ws\n", n); + lwsl_err("ERROR %d writing to ws\n", m); return -1; }