From 1b42ce738f4c3e260f79bcb143bfe6efcdce5709 Mon Sep 17 00:00:00 2001 From: Adrian DC Date: Thu, 23 Apr 2020 22:06:14 +0200 Subject: [PATCH 01/10] feat: implement #45: add support for logging configuration --- API.md | 13 +++++++++++++ src/internal/sio_client_impl.cpp | 16 ++++++++++++++++ src/internal/sio_client_impl.h | 8 +++++++- src/sio_client.cpp | 17 ++++++++++++++++- src/sio_client.h | 8 +++++++- 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index 1061fc74..f1280eb4 100644 --- a/API.md +++ b/API.md @@ -168,6 +168,19 @@ Set listener for reconnecting is in process. Set listener for reconnecting event, called once a delayed connecting is scheduled. +#### Logs +`void set_logs_default()` + +Configure logs to the default level (connect, disconnect, app) + +`void set_logs_quiet()` + +Configure logs to the quiet level + +`void set_logs_verbose()` + +Configure logs to the verbose level + #### Namespace `socket::ptr socket(std::string const& nsp)` diff --git a/src/internal/sio_client_impl.cpp b/src/internal/sio_client_impl.cpp index f78aea49..d79681e7 100644 --- a/src/internal/sio_client_impl.cpp +++ b/src/internal/sio_client_impl.cpp @@ -164,6 +164,22 @@ namespace sio } } + void client_impl::set_logs_default() + { + m_client.clear_access_channels(websocketpp::log::alevel::all); + m_client.set_access_channels(websocketpp::log::alevel::connect | websocketpp::log::alevel::disconnect | websocketpp::log::alevel::app); + } + + void client_impl::set_logs_quiet() + { + m_client.clear_access_channels(websocketpp::log::alevel::all); + } + + void client_impl::set_logs_verbose() + { + m_client.set_access_channels(websocketpp::log::alevel::all); + } + /*************************protected:*************************/ void client_impl::send(packet& p) { diff --git a/src/internal/sio_client_impl.h b/src/internal/sio_client_impl.h index bfdc0abc..34db1869 100644 --- a/src/internal/sio_client_impl.h +++ b/src/internal/sio_client_impl.h @@ -122,7 +122,13 @@ namespace sio void set_reconnect_delay(unsigned millis) {m_reconn_delay = millis;if(m_reconn_delay_maxmillis) m_reconn_delay = millis;} - + + void set_logs_default(); + + void set_logs_quiet(); + + void set_logs_verbose(); + protected: void send(packet& p); diff --git a/src/sio_client.cpp b/src/sio_client.cpp index d85f7bfe..b475e6f7 100644 --- a/src/sio_client.cpp +++ b/src/sio_client.cpp @@ -123,5 +123,20 @@ namespace sio { m_impl->set_reconnect_delay_max(millis); } - + + void client::set_logs_default() + { + m_impl->set_logs_default(); + } + + void client::set_logs_quiet() + { + m_impl->set_logs_quiet(); + } + + void client::set_logs_verbose() + { + m_impl->set_logs_verbose(); + } + } diff --git a/src/sio_client.h b/src/sio_client.h index 77be0a2d..c37882ab 100644 --- a/src/sio_client.h +++ b/src/sio_client.h @@ -66,7 +66,13 @@ namespace sio void set_reconnect_delay(unsigned millis); void set_reconnect_delay_max(unsigned millis); - + + void set_logs_default(); + + void set_logs_quiet(); + + void set_logs_verbose(); + sio::socket::ptr const& socket(const std::string& nsp = ""); // Closes the connection From b196fa7537cd3f7bed626ead873a7b71d1293c0d Mon Sep 17 00:00:00 2001 From: DK Moon Date: Mon, 27 Feb 2017 05:12:30 +0000 Subject: [PATCH 02/10] fix: lower the minimum CMake supported version If CMake doesn't understand C++11-related property, simply use the COMPILE_FLAGS property --- CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19c5e54d..f0bd6957 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) +cmake_minimum_required(VERSION 2.8 FATAL_ERROR) PROJECT(sioclient) option(BUILD_SHARED_LIBS "Build the shared library" OFF) @@ -39,9 +39,12 @@ target_include_directories(sioclient PRIVATE ${CMAKE_CURRENT_LIST_DIR}/lib/asio/asio/include ) +if (CMAKE_VERSION VERSION_GREATER "3.1") set_property(TARGET sioclient PROPERTY CXX_STANDARD 11) set_property(TARGET sioclient PROPERTY CXX_STANDARD_REQUIRED ON) - +else() +set_property(TARGET sioclient APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++11") +endif() if(BUILD_SHARED_LIBS) set_target_properties(sioclient PROPERTIES @@ -62,9 +65,13 @@ target_include_directories(sioclient_tls PRIVATE ${OPENSSL_INCLUDE_DIR} ) +if (CMAKE_VERSION VERSION_GREATER "3.1") set_property(TARGET sioclient_tls PROPERTY CXX_STANDARD 11) set_property(TARGET sioclient_tls PROPERTY CXX_STANDARD_REQUIRED ON) target_link_libraries(sioclient_tls PRIVATE ${OPENSSL_LIBRARIES} ) +else() +set_property(TARGET sioclient_tls APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++11") +endif() target_compile_definitions(sioclient_tls PRIVATE -DSIO_TLS) if(BUILD_SHARED_LIBS) set_target_properties(sioclient_tls From d1c73b73a8f536da3d353eac2a560af9791b13e3 Mon Sep 17 00:00:00 2001 From: Adrian DC Date: Fri, 5 Feb 2021 22:30:56 +0100 Subject: [PATCH 03/10] fix: resolve #254: handle closing sockets upon on_fail events --- src/internal/sio_client_impl.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/internal/sio_client_impl.cpp b/src/internal/sio_client_impl.cpp index d79681e7..32dd4a46 100644 --- a/src/internal/sio_client_impl.cpp +++ b/src/internal/sio_client_impl.cpp @@ -382,6 +382,12 @@ namespace sio void client_impl::on_fail(connection_hdl) { + if (m_con_state == con_closing) { + LOG("Connection failed while closing." << endl); + this->close(); + return; + } + m_con.reset(); m_con_state = con_closed; this->sockets_invoke_void(&sio::socket::on_disconnect); @@ -404,6 +410,12 @@ namespace sio void client_impl::on_open(connection_hdl con) { + if (m_con_state == con_closing) { + LOG("Connection opened while closing." << endl); + this->close(); + return; + } + LOG("Connected." << endl); m_con_state = con_opened; m_con = con; From e7de4ebf64f4f49e18594a2c093c07beb963579a Mon Sep 17 00:00:00 2001 From: Adrian DC Date: Fri, 5 Feb 2021 23:25:13 +0100 Subject: [PATCH 04/10] fix: resolve client_impl::ping LOG call syntax in debug builds --- src/internal/sio_client_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/sio_client_impl.cpp b/src/internal/sio_client_impl.cpp index 32dd4a46..b9de3449 100644 --- a/src/internal/sio_client_impl.cpp +++ b/src/internal/sio_client_impl.cpp @@ -302,7 +302,7 @@ namespace sio if(ec || m_con.expired()) { if (ec != asio::error::operation_aborted) - LOG("ping exit,con is expired?"< Date: Sun, 14 Feb 2021 00:01:35 -0600 Subject: [PATCH 05/10] feat: allow resource path to be set in connection URI (#134) Please note that this implementation differs from the JS one, where the resource path is the namespace you want to reach: ```js const socket = io("https://example.com/my-namespace", { path: "/my-custom-path/" }); ``` Here, we will have: ```C++ sio::client h; h.connect("https://example.com/my-custom-path/"); h.socket("/my-namespace")->emit("hello"); ``` --- src/internal/sio_client_impl.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/internal/sio_client_impl.cpp b/src/internal/sio_client_impl.cpp index b9de3449..1f91d5a9 100644 --- a/src/internal/sio_client_impl.cpp +++ b/src/internal/sio_client_impl.cpp @@ -238,7 +238,12 @@ namespace sio } else { ss<0){ ss<<"&sid="< Date: Wed, 24 Mar 2021 21:40:14 +0000 Subject: [PATCH 06/10] docs: fix title format (#297) --- examples/QT/README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/QT/README.md b/examples/QT/README.md index 03ccb8ec..f39c4052 100644 --- a/examples/QT/README.md +++ b/examples/QT/README.md @@ -2,7 +2,7 @@ In this tutorial we’ll learn how to create a QT chat application that communicates with a [Socket.IO Node.JS chat server](https://github.com/Automattic/socket.io/tree/master/examples/chat). -###Introduction +### Introduction To follow along, start by cloning the repository: [socket.io-client-cpp](https://github.com/socketio/socket.io-client-cpp). Using: @@ -39,7 +39,7 @@ SioChatDemo |__mainwindow.ui ``` -###Import SioClient and config compile options. +### Import SioClient and config compile options. Let's copy the SioClient into the QT project as a subfolder `sioclient`. Edit `SioChatDemo.pro` to config paths and compile options, simply add: @@ -82,7 +82,7 @@ else:win32:CONFIG(debug, debug|release): LIBS += -L`our Win32 boost static lib f else:unix: LIBS += -L`our osx boost static lib folder` -lboost ``` -###Make up mainwindow ui. +### Make up mainwindow ui. Make up a simple ui by drag and drop widget from `Widget box` in left side. We finally end up with this: @@ -101,7 +101,7 @@ It contains: * a `QPushButton` at the bottomright for sending message, named `sendBtn` -###Add Slots in mainwindow +### Add Slots in mainwindow Slots need to be added in `mainwindow` class to handle UI events.They are * click login button @@ -122,7 +122,7 @@ public Q_SLOTS: void OnMessageReturn(); ``` -###Connect UI event signal and slots together +### Connect UI event signal and slots together Open `mainwindow.ui` in Design mode. switch to `signals/slots` mode by check `Menu->Edit->Edit Signals/Slots` By press left mouse on widget and drag on to the window (cursor will become a sign of electrical ground), to open the connection editor. @@ -135,7 +135,7 @@ We finally end up with this: ![QT signals&slots](https://cldup.com/Vsb-UXG3FC.jpg) -###Adding UI refresh Signals/Slots +### Adding UI refresh Signals/Slots `sio::client`'s callbacks are not in UI thread. However, UI is required to be updated by those callbacks, so we need some `Signal` for non-UI thread to "request" `Slots` functions been called in UI thread. Say if we want to signal `QListWidgetItem` being added, add: ```C++ @@ -160,7 +160,7 @@ Then connect them in `MainWindow` constructor. connect(this,SIGNAL(RequestAddListItem(QListWidgetItem*)),this,SLOT(AddListItem(QListWidgetItem*))); ``` -###Init sio::client in MainWindow +### Init sio::client in MainWindow For single window applications, simply let `MainWindow` class holding the `sio::client` object: declare a `unique_ptr` member of `sio::client` and Several event handling functions in `mainwindow.h` @@ -214,7 +214,7 @@ MainWindow::MainWindow(QWidget *parent) : } ``` -###Managing connection state +### Managing connection state We have several connection listeners for connection events. First we want to send login message once we're connected, get the default `socket` from `client` to do that. @@ -256,7 +256,7 @@ MainWindow::~MainWindow() } ``` -###Handle socket.io events +### Handle socket.io events We'll need to handle socket.io events in our functions bind to socket.io events. For example, we need to show received messages to the `listView` @@ -278,7 +278,7 @@ void MainWindow::OnNewMessage(std::string const& name,message::ptr const& data,b } ``` -###Sending chat message +### Sending chat message When `sendBtn` is clicked, we need to send the text in `messageEdit` to chatroom. Add code to `SendBtnClicked()`: @@ -301,7 +301,7 @@ void MainWindow::SendBtnClicked() } ``` -###Further reading +### Further reading You can run [Demo project](https://github.com/socketio/socket.io-client-cpp/tree/master/examples/QT/SioChatDemo) to have a closer look. Before running, please follow the [instructions](../../README.md#with_cmake) to make the sioclient library. From 0581aaba021066706da7ca637977553733f7d38e Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 24 Mar 2021 22:40:33 +0100 Subject: [PATCH 07/10] docs: update compatibility table for Socket.IO v4 The v4 contains only a few breaking changes at the API level on the server-side, so the current C++ client is compatible. Reference: https://socket.io/docs/v4/migrating-from-3-x-to-4-0/ --- README.md | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 46c9e5ed..5a68967f 100755 --- a/README.md +++ b/README.md @@ -8,10 +8,26 @@ By virtue of being written in C++, this client works in several different platfo ## Compatibility table -| C++ Client version | Socket.IO server version | -| ------------------- | ------------------------ | -| 2.x (`2.x` branch) | 1.x / 2.x | -| 3.x (master branch) | 3.x | + + + + + + + + + + + + + + + + + + + +
C++ Client versionSocket.IO server version
1.x / 2.x3.x / 4.x
2.x (2.x branch)YESYES, with allowEIO3: true
3.x (master branch)NOYES
## Features From e8ea70776dc0902725b38d1f988fbadc40474d14 Mon Sep 17 00:00:00 2001 From: Johny Qiu Date: Fri, 11 Jun 2021 17:15:24 +0800 Subject: [PATCH 08/10] feat: use TLSv2 when TLS is used (#310) --- src/internal/sio_client_impl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/internal/sio_client_impl.cpp b/src/internal/sio_client_impl.cpp index 1f91d5a9..8bf90f97 100644 --- a/src/internal/sio_client_impl.cpp +++ b/src/internal/sio_client_impl.cpp @@ -599,10 +599,9 @@ namespace sio #if SIO_TLS client_impl::context_ptr client_impl::on_tls_init(connection_hdl conn) { - context_ptr ctx = context_ptr(new asio::ssl::context(asio::ssl::context::tlsv1)); + context_ptr ctx = context_ptr(new asio::ssl::context(asio::ssl::context::tlsv12)); asio::error_code ec; ctx->set_options(asio::ssl::context::default_workarounds | - asio::ssl::context::no_sslv2 | asio::ssl::context::single_dh_use,ec); if(ec) { From 82d39a90ef118500a0329d214eec331db983bd74 Mon Sep 17 00:00:00 2001 From: Chris Grahn Date: Thu, 2 Sep 2021 01:40:06 -0500 Subject: [PATCH 09/10] feat: support TLSv1.2 and newer (#321) --- src/internal/sio_client_impl.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/internal/sio_client_impl.cpp b/src/internal/sio_client_impl.cpp index 8bf90f97..53cfe539 100644 --- a/src/internal/sio_client_impl.cpp +++ b/src/internal/sio_client_impl.cpp @@ -599,10 +599,12 @@ namespace sio #if SIO_TLS client_impl::context_ptr client_impl::on_tls_init(connection_hdl conn) { - context_ptr ctx = context_ptr(new asio::ssl::context(asio::ssl::context::tlsv12)); + context_ptr ctx = context_ptr(new asio::ssl::context(asio::ssl::context::tls)); asio::error_code ec; ctx->set_options(asio::ssl::context::default_workarounds | - asio::ssl::context::single_dh_use,ec); + asio::ssl::context::no_tlsv1 | + asio::ssl::context::no_tlsv1_1 | + asio::ssl::context::single_dh_use,ec); if(ec) { cerr<<"Init tls failed,reason:"<< ec.message()< Date: Tue, 12 Oct 2021 10:24:29 +0200 Subject: [PATCH 10/10] chore(release): 3.1.0 --- CHANGELOG.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..286b43b1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,25 @@ +# [3.1.0](https://github.com/socketio/socket.io-client-cpp/compare/3.0.0...3.1.0) (2021-10-12) + + +### Bug Fixes + +* lower the minimum CMake supported version ([b196fa7](https://github.com/socketio/socket.io-client-cpp/commit/b196fa7537cd3f7bed626ead873a7b71d1293c0d)) +* handle closing sockets upon on_fail events ([d1c73b7](https://github.com/socketio/socket.io-client-cpp/commit/d1c73b73a8f536da3d353eac2a560af9791b13e3)) +* resolve client_impl::ping LOG call syntax in debug builds ([e7de4eb](https://github.com/socketio/socket.io-client-cpp/commit/e7de4ebf64f4f49e18594a2c093c07beb963579a)) + + +### Features + +* allow resource path to be set in connection URI ([#134](https://github.com/socketio/socket.io-client-cpp/issues/134)) ([36a8cd4](https://github.com/socketio/socket.io-client-cpp/commit/36a8cd45272aa51f0f6ef27aa4744dbc6e8421f7)) +* add support for logging configuration ([1b42ce7](https://github.com/socketio/socket.io-client-cpp/commit/1b42ce738f4c3e260f79bcb143bfe6efcdce5709)) +* support TLSv1.2 and newer ([#321](https://github.com/socketio/socket.io-client-cpp/issues/321)) ([82d39a9](https://github.com/socketio/socket.io-client-cpp/commit/82d39a90ef118500a0329d214eec331db983bd74)) + + + +# [3.0.0](https://github.com/socketio/socket.io-client-cpp/compare/2.0.0...3.0.0) (2021-01-09) + + +### Features + +* add support for Socket.IO v3 ([ec4d540](https://github.com/socketio/socket.io-client-cpp/commit/ec4d540ad54593604ac2091e67ffc2a6d9a00db6)) +