From e8313084f9e8b064433cb10eb9a79bf87407fab6 Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin Date: Mon, 12 Sep 2022 22:16:56 +0300 Subject: Add minimal WebSocket server implementation for evhttp (#1322) This adds few functions to use evhttp-based webserver to handle incoming WebSockets connections. We've tried to use both libevent and libwebsockets in our application, but found that we need to have different ports at the same time to handle standard HTTP and WebSockets traffic. This change can help to stick only with libevent library. Implementation was inspired by modified Libevent source code in ipush project [1]. [1]: https://github.com/sqfasd/ipush/tree/master/deps/libevent-2.0.21-stable Also, WebSocket-based chat server was added as a sample. --- CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 100d7703..8ada925c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -820,6 +820,7 @@ set(HDR_PRIVATE util-internal.h openssl-compat.h evconfig-private.h + sha1.h compat/sys/queue.h) set(HDR_COMPAT @@ -854,6 +855,7 @@ set(HDR_PUBLIC include/event2/tag_compat.h include/event2/thread.h include/event2/util.h + include/event2/ws.h include/event2/visibility.h ${PROJECT_BINARY_DIR}/include/event2/event-config.h) @@ -966,8 +968,12 @@ set(SRC_EXTRA event_tagging.c http.c evdns.c + ws.c + sha1.c evrpc.c) +set_source_files_properties(sha1.c PROPERTIES COMPILE_FLAGS + -D${CMAKE_C_BYTE_ORDER}=1) add_definitions(-DHAVE_CONFIG_H) # We use BEFORE here so we don't accidentally look in system directories @@ -1134,6 +1140,7 @@ if (NOT EVENT__DISABLE_SAMPLES) set(SAMPLES_WOPT dns-example + ws-chat-server http-server ) foreach (SAMPLE ${SAMPLES_WOPT}) @@ -1217,6 +1224,7 @@ if (NOT EVENT__DISABLE_TESTS) test/regress_et.c test/regress_finalize.c test/regress_http.c + test/regress_http.h test/regress_listener.c test/regress_main.c test/regress_minheap.c @@ -1225,6 +1233,8 @@ if (NOT EVENT__DISABLE_TESTS) test/regress_testutils.h test/regress_util.c test/regress_watch.c + test/regress_ws.c + test/regress_ws.h test/tinytest.c) if (WIN32) -- cgit v1.2.1