Compare commits
	
		
			7 Commits
		
	
	
		
			feature/ci
			...
			bug/docker
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | e31b913280 | ||
|  | 39cc0ed32f | ||
|  | 22c3a7264e | ||
|  | ee5a2eb46e | ||
|  | f6e34e4b34 | ||
|  | d0359a1764 | ||
|  | 8910ebcc3c | 
							
								
								
									
										10
									
								
								.github/workflows/unittest_uwp.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								.github/workflows/unittest_uwp.yml
									
									
									
									
										vendored
									
									
								
							| @@ -10,11 +10,17 @@ jobs: | ||||
|     steps: | ||||
|     - uses: actions/checkout@v1 | ||||
|     - uses: seanmiddleditch/gha-setup-vsdevenv@master | ||||
|     - uses: seanmiddleditch/gha-setup-ninja@master | ||||
|     - run: | | ||||
|         mkdir build | ||||
|         cd build | ||||
|         cmake -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION="10.0" -DCMAKE_CXX_COMPILER=cl.exe -DUSE_TEST=1 -DUSE_ZLIB=0 .. | ||||
|     - run: cmake --build build | ||||
|         cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION="10.0" -DCMAKE_CXX_COMPILER=cl.exe -DCMAKE_C_COMPILER=cl.exe -DUSE_TEST=1 -DUSE_ZLIB=0 .. | ||||
|     - run: | | ||||
|         cd build | ||||
|         ninja | ||||
|     - run: | | ||||
|         cd build | ||||
|         ninja test | ||||
|  | ||||
| # | ||||
| #   Windows with OpenSSL is working but disabled as it takes 13 minutes (10 for openssl) to build with vcpkg | ||||
|   | ||||
							
								
								
									
										10
									
								
								.github/workflows/unittest_windows.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								.github/workflows/unittest_windows.yml
									
									
									
									
										vendored
									
									
								
							| @@ -10,11 +10,17 @@ jobs: | ||||
|     steps: | ||||
|     - uses: actions/checkout@v1 | ||||
|     - uses: seanmiddleditch/gha-setup-vsdevenv@master | ||||
|     - uses: seanmiddleditch/gha-setup-ninja@master | ||||
|     - run: | | ||||
|         mkdir build | ||||
|         cd build | ||||
|         cmake -DCMAKE_CXX_COMPILER=cl.exe -DUSE_WS=1 -DUSE_TEST=1 -DUSE_ZLIB=0 .. | ||||
|     - run: cmake --build build | ||||
|         cmake -GNinja -DCMAKE_CXX_COMPILER=cl.exe -DCMAKE_C_COMPILER=cl.exe -DUSE_WS=1 -DUSE_TEST=1 -DUSE_ZLIB=0 .. | ||||
|     - run: | | ||||
|         cd build | ||||
|         ninja | ||||
|     - run: | | ||||
|         cd build | ||||
|         ninja test | ||||
|  | ||||
| #- run: ../build/test/ixwebsocket_unittest.exe | ||||
| # working-directory: test | ||||
|   | ||||
| @@ -17,7 +17,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") | ||||
| endif() | ||||
|  | ||||
| if (UNIX) | ||||
|   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") | ||||
|   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -gz") | ||||
| endif() | ||||
|  | ||||
| if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") | ||||
|   | ||||
| @@ -77,6 +77,8 @@ IXWebSocket is actively being developed, check out the [changelog](https://machi | ||||
|  | ||||
| IXWebSocket client code is autobahn compliant beginning with the 6.0.0 version. See the current [test results](https://bsergean.github.io/autobahn/reports/clients/index.html). Some tests are still failing in the server code. | ||||
|  | ||||
| Starting with the 11.0.8 release, IXWebSocket should be fully C++11 compatible. | ||||
|  | ||||
| ## Users | ||||
|  | ||||
| If your company or project is using this library, feel free to open an issue or PR to amend this list. | ||||
| @@ -113,6 +115,10 @@ To check the performance of a websocket library, you can look at the [autoroute] | ||||
| | UWP               | Disabled          | None              | [![Build2][6]][0] | | ||||
| | Linux             | OpenSSL           | Address Sanitizer | [![Build2][7]][0] | | ||||
|  | ||||
| * ASAN fails on Linux because of a known problem, we need a  | ||||
| * Some tests are disabled on Windows/UWP because of a pathing problem | ||||
| * TLS and ZLIB are disabled on Windows/UWP because enabling make the CI run takes a lot of time, for setting up vcpkg. | ||||
|  | ||||
| [0]: https://github.com/machinezone/IXWebSocket | ||||
| [1]: https://github.com/machinezone/IXWebSocket/workflows/linux/badge.svg | ||||
| [2]: https://github.com/machinezone/IXWebSocket/workflows/mac_tsan_sectransport/badge.svg | ||||
|   | ||||
							
								
								
									
										7
									
								
								build.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								build.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| #!/bin/sh | ||||
|  | ||||
| rm -rf build | ||||
| mkdir -p build  | ||||
| cd build  | ||||
| cmake -GNinja -DCMAKE_UNITY_BUILD=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 -DUSE_TEST=OFF ..  | ||||
| ninja | ||||
| @@ -1,39 +1,25 @@ | ||||
| FROM alpine:3.12 as build | ||||
| # Build time | ||||
| # | ||||
| # Build with | ||||
| # docker build --ssh default -t ws . | ||||
| # | ||||
| # focal == ubuntu 2020.04 | ||||
| # groovy == ubuntu 2020.10 | ||||
| FROM ubuntu:groovy | ||||
|  | ||||
| RUN apk add --no-cache \ | ||||
|     gcc g++ musl-dev linux-headers \ | ||||
|     cmake mbedtls-dev make zlib-dev python3-dev ninja git | ||||
| RUN apt update | ||||
|  | ||||
| RUN addgroup -S app && \ | ||||
|     adduser -S -G app app && \ | ||||
|     chown -R app:app /opt && \ | ||||
|     chown -R app:app /usr/local | ||||
| RUN apt-get -y install g++ cmake make automake ccache libtool flex bison pkg-config git python3 jq | ||||
| RUN apt-get -y install libjemalloc-dev libssl-dev libmcrypt-dev mcrypt zlib1g lua5.1-dev uuid-dev libz-dev binutils-dev | ||||
| RUN apt-get -y install libboost-dev libboost-test-dev libboost-program-options-dev libboost-all-dev libboost-regex-dev  | ||||
| RUN apt-get -y install ninja-build | ||||
|  | ||||
| # There is a bug in CMake where we cannot build from the root top folder | ||||
| # So we build from /opt | ||||
| COPY --chown=app:app . /opt | ||||
| COPY . /opt | ||||
| WORKDIR /opt | ||||
|  | ||||
| USER app | ||||
| RUN make -f makefile.dev ws_mbedtls_install && \ | ||||
|     sh tools/trim_repo_for_docker.sh | ||||
| RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts | ||||
| RUN rm -rf build | ||||
| RUN --mount=type=ssh ./build.sh | ||||
|  | ||||
| FROM alpine:3.12 as runtime | ||||
|  | ||||
| RUN apk add --no-cache libstdc++ mbedtls ca-certificates python3 strace && \ | ||||
|     addgroup -S app && \ | ||||
|     adduser -S -G app app | ||||
|  | ||||
| COPY --chown=app:app --from=build /usr/local/bin/ws /usr/local/bin/ws | ||||
|  | ||||
| # COPY --chown=app:app --from=build /opt /opt | ||||
|  | ||||
| RUN chmod +x /usr/local/bin/ws && \ | ||||
|     ldd /usr/local/bin/ws | ||||
|  | ||||
| # Now run in usermode | ||||
| USER app | ||||
| WORKDIR /home/app | ||||
|  | ||||
| ENTRYPOINT ["ws"] | ||||
| EXPOSE 8008 | ||||
| COPY /opt/build/ws/ws /usr/local/bin/ws | ||||
| CMD ["/usr/local/bin/ws"] | ||||
|   | ||||
| @@ -97,9 +97,10 @@ namespace ix | ||||
|         } | ||||
|         else if (_onClientMessageCallback) | ||||
|         { | ||||
|             WebSocket* webSocketRawPtr = webSocket.get(); | ||||
|             webSocket->setOnMessageCallback( | ||||
|                 [this, &ws = *webSocket.get(), connectionState](const WebSocketMessagePtr& msg) { | ||||
|                     _onClientMessageCallback(connectionState, ws, msg); | ||||
|                 [this, webSocketRawPtr, connectionState](const WebSocketMessagePtr& msg) { | ||||
|                     _onClientMessageCallback(connectionState, *webSocketRawPtr, msg); | ||||
|                 }); | ||||
|         } | ||||
|         else | ||||
| @@ -168,4 +169,46 @@ namespace ix | ||||
|         std::lock_guard<std::mutex> lock(_clientsMutex); | ||||
|         return _clients.size(); | ||||
|     } | ||||
|  | ||||
|     // | ||||
|     // Classic servers | ||||
|     // | ||||
|     void WebSocketServer::makeBroadcastServer() | ||||
|     { | ||||
|         setOnClientMessageCallback( | ||||
|             [this](std::shared_ptr<ConnectionState> connectionState, | ||||
|                    WebSocket& webSocket, | ||||
|                    const WebSocketMessagePtr& msg) { | ||||
|                 auto remoteIp = connectionState->getRemoteIp(); | ||||
|                 if (msg->type == ix::WebSocketMessageType::Message) | ||||
|                 { | ||||
|                     for (auto&& client : getClients()) | ||||
|                     { | ||||
|                         if (client.get() != &webSocket) | ||||
|                         { | ||||
|                             client->send(msg->str, msg->binary); | ||||
|  | ||||
|                             // Make sure the OS send buffer is flushed before moving on | ||||
|                             do | ||||
|                             { | ||||
|                                 size_t bufferedAmount = client->bufferedAmount(); | ||||
|                                 std::chrono::duration<double, std::milli> duration(500); | ||||
|                                 std::this_thread::sleep_for(duration); | ||||
|                             } while (client->bufferedAmount() != 0); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             }); | ||||
|     } | ||||
|  | ||||
|     int WebSocketServer::listenAndStart() | ||||
|     { | ||||
|         auto res = listen(); | ||||
|         if (!res.first) | ||||
|         { | ||||
|             return 1; | ||||
|         } | ||||
|  | ||||
|         start(); | ||||
|     } | ||||
| } // namespace ix | ||||
|   | ||||
| @@ -47,6 +47,9 @@ namespace ix | ||||
|         // Get all the connected clients | ||||
|         std::set<std::shared_ptr<WebSocket>> getClients(); | ||||
|  | ||||
|         void makeBroadcastServer(); | ||||
|         int listenAndStart(); | ||||
|  | ||||
|         const static int kDefaultHandShakeTimeoutSecs; | ||||
|  | ||||
|     private: | ||||
|   | ||||
| @@ -17,14 +17,11 @@ set (TEST_TARGET_NAMES | ||||
|   IXWebSocketTestConnectionDisconnection | ||||
|   IXUrlParserTest | ||||
|   IXHttpClientTest | ||||
|   IXHttpServerTest | ||||
|   IXUnityBuildsTest | ||||
|   IXHttpTest | ||||
|   IXDNSLookupTest | ||||
|   IXWebSocketSubProtocolTest | ||||
|   IXWebSocketChatTest | ||||
|   # IXWebSocketBroadcastTest ## FIXME was depending on cobra / take a broadcast server from ws | ||||
|   IXWebSocketPerMessageDeflateCompressorTest | ||||
|   IXStrCaseCompareTest | ||||
| ) | ||||
|  | ||||
| @@ -33,6 +30,17 @@ set (TEST_TARGET_NAMES | ||||
| if (UNIX) | ||||
|   list(APPEND TEST_TARGET_NAMES | ||||
|     IXWebSocketCloseTest | ||||
|  | ||||
|     # Fail on Windows in CI probably because the pathing is wrong and | ||||
|     # some resource files cannot be found | ||||
|     IXHttpServerTest | ||||
|     IXWebSocketChatTest | ||||
|   ) | ||||
| endif() | ||||
|  | ||||
| if (USE_ZLIB) | ||||
|   list(APPEND TEST_TARGET_NAMES | ||||
|     IXWebSocketPerMessageDeflateCompressorTest | ||||
|   ) | ||||
| endif() | ||||
|  | ||||
|   | ||||
| @@ -29,6 +29,7 @@ namespace ix | ||||
|  | ||||
|             // Comparison should be case insensitive | ||||
|             REQUIRE(httpHeaders["Foo"] == "foo"); | ||||
|             REQUIRE(httpHeaders["Foo"] != "bar"); | ||||
|         } | ||||
|  | ||||
|         SECTION("2") | ||||
| @@ -39,7 +40,7 @@ namespace ix | ||||
|  | ||||
|             headers["Upgrade"] = "webSocket"; | ||||
|  | ||||
|             REQUIRE(CaseInsensitiveLess::cmp(headers["upgrade"], "WebSocket") == 0); | ||||
|             REQUIRE(!CaseInsensitiveLess::cmp(headers["upGRADE"], "webSocket")); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
							
								
								
									
										102
									
								
								ws/ws.cpp
									
									
									
									
									
								
							
							
						
						
									
										102
									
								
								ws/ws.cpp
									
									
									
									
									
								
							| @@ -439,93 +439,6 @@ namespace ix | ||||
|         return generateReport(url) ? 0 : 1; | ||||
|     } | ||||
|  | ||||
|     // | ||||
|     //  broadcast server | ||||
|     // | ||||
|     int ws_broadcast_server_main(int port, | ||||
|                                  const std::string& hostname, | ||||
|                                  const ix::SocketTLSOptions& tlsOptions) | ||||
|     { | ||||
|         spdlog::info("Listening on {}:{}", hostname, port); | ||||
|  | ||||
|         ix::WebSocketServer server(port, hostname); | ||||
|         server.setTLSOptions(tlsOptions); | ||||
|  | ||||
|         server.setOnClientMessageCallback( | ||||
|             [&server](std::shared_ptr<ConnectionState> connectionState, | ||||
|                       WebSocket& webSocket, | ||||
|                       const WebSocketMessagePtr& msg) { | ||||
|                 auto remoteIp = connectionState->getRemoteIp(); | ||||
|                 if (msg->type == ix::WebSocketMessageType::Open) | ||||
|                 { | ||||
|                     spdlog::info("New connection"); | ||||
|                     spdlog::info("remote ip: {}", remoteIp); | ||||
|                     spdlog::info("id: {}", connectionState->getId()); | ||||
|                     spdlog::info("Uri: {}", msg->openInfo.uri); | ||||
|                     spdlog::info("Headers:"); | ||||
|                     for (auto it : msg->openInfo.headers) | ||||
|                     { | ||||
|                         spdlog::info("{}: {}", it.first, it.second); | ||||
|                     } | ||||
|                 } | ||||
|                 else if (msg->type == ix::WebSocketMessageType::Close) | ||||
|                 { | ||||
|                     spdlog::info("Closed connection: code {} reason {}", | ||||
|                                  msg->closeInfo.code, | ||||
|                                  msg->closeInfo.reason); | ||||
|                 } | ||||
|                 else if (msg->type == ix::WebSocketMessageType::Error) | ||||
|                 { | ||||
|                     std::stringstream ss; | ||||
|                     ss << "Connection error: " << msg->errorInfo.reason << std::endl; | ||||
|                     ss << "#retries: " << msg->errorInfo.retries << std::endl; | ||||
|                     ss << "Wait time(ms): " << msg->errorInfo.wait_time << std::endl; | ||||
|                     ss << "HTTP Status: " << msg->errorInfo.http_status << std::endl; | ||||
|                     spdlog::info(ss.str()); | ||||
|                 } | ||||
|                 else if (msg->type == ix::WebSocketMessageType::Fragment) | ||||
|                 { | ||||
|                     spdlog::info("Received message fragment"); | ||||
|                 } | ||||
|                 else if (msg->type == ix::WebSocketMessageType::Message) | ||||
|                 { | ||||
|                     spdlog::info("Received {} bytes", msg->wireSize); | ||||
|  | ||||
|                     for (auto&& client : server.getClients()) | ||||
|                     { | ||||
|                         if (client.get() != &webSocket) | ||||
|                         { | ||||
|                             client->send(msg->str, msg->binary, [](int current, int total) -> bool { | ||||
|                                 spdlog::info("Step {} out of {}", current, total); | ||||
|                                 return true; | ||||
|                             }); | ||||
|  | ||||
|                             do | ||||
|                             { | ||||
|                                 size_t bufferedAmount = client->bufferedAmount(); | ||||
|                                 spdlog::info("{} bytes left to be sent", bufferedAmount); | ||||
|  | ||||
|                                 std::chrono::duration<double, std::milli> duration(500); | ||||
|                                 std::this_thread::sleep_for(duration); | ||||
|                             } while (client->bufferedAmount() != 0); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             }); | ||||
|  | ||||
|         auto res = server.listen(); | ||||
|         if (!res.first) | ||||
|         { | ||||
|             spdlog::info(res.second); | ||||
|             return 1; | ||||
|         } | ||||
|  | ||||
|         server.start(); | ||||
|         server.wait(); | ||||
|  | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     /* | ||||
|      *  ws_chat.cpp | ||||
|      *  Author: Benjamin Sergeant | ||||
| @@ -988,6 +901,9 @@ namespace ix | ||||
|  | ||||
|         auto addr = res->ai_addr; | ||||
|  | ||||
|         // FIXME: this display weird addresses / we could steal libuv inet.c | ||||
|         // code which display correct results | ||||
|  | ||||
|         char str[INET_ADDRSTRLEN]; | ||||
|         inet_ntop(AF_INET, &addr, str, INET_ADDRSTRLEN); | ||||
|  | ||||
| @@ -2853,9 +2769,13 @@ int main(int argc, char** argv) | ||||
|         ret = ix::ws_push_server( | ||||
|             port, hostname, tlsOptions, ipv6, disablePerMessageDeflate, disablePong, sendMsg); | ||||
|     } | ||||
|     else if (app.got_subcommand("transfer")) | ||||
|     else if (app.got_subcommand("transfer") || app.got_subcommand("broadcast_server")) | ||||
|     { | ||||
|         ret = ix::ws_transfer_main(port, hostname, tlsOptions); | ||||
|         ix::WebSocketServer server(port, hostname); | ||||
|         server.setTLSOptions(tlsOptions); | ||||
|         server.makeBroadcastServer(); | ||||
|         server.listenAndStart(); | ||||
|         server.wait(); | ||||
|     } | ||||
|     else if (app.got_subcommand("send")) | ||||
|     { | ||||
| @@ -2870,10 +2790,6 @@ int main(int argc, char** argv) | ||||
|     { | ||||
|         ret = ix::ws_chat_main(url, user); | ||||
|     } | ||||
|     else if (app.got_subcommand("broadcast_server")) | ||||
|     { | ||||
|         ret = ix::ws_broadcast_server_main(port, hostname, tlsOptions); | ||||
|     } | ||||
|     else if (app.got_subcommand("ping")) | ||||
|     { | ||||
|         ret = ix::ws_ping_pong_main(url, tlsOptions); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user