From dc045baffe7e355e86af3c73d4e676f9c7c229c0 Mon Sep 17 00:00:00 2001 From: Vincent Raman Date: Thu, 3 Sep 2015 17:54:47 +0200 Subject: [PATCH 1/6] Add options to choose between static and dynamic libraries --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b704043..e671da66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) PROJECT(sioclient) +option(BUILD_SHARED_LIBS "Build the shared library" OFF) +option(Boost_USE_STATIC_LIBS "Use Boost static version" ON) + if(NOT CMAKE_BUILD_TYPE ) MESSAGE(STATUS "not define build type, set to release" ) set(CMAKE_BUILD_TYPE Release ) @@ -11,7 +14,6 @@ endif() set(BOOST_VER "1.55.0" CACHE STRING "boost version" ) -set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) find_package(Boost ${BOOST_VER} REQUIRED COMPONENTS system date_time random) @@ -21,7 +23,7 @@ aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/src/internal ALL_SRC) file(GLOB ALL_HEADERS ${CMAKE_CURRENT_LIST_DIR}/src/*.h ) set(SIO_INCLUDEDIR ${CMAKE_CURRENT_LIST_DIR}) -add_library(sioclient STATIC ${ALL_SRC}) +add_library(sioclient ${ALL_SRC}) target_include_directories(sioclient PRIVATE ${Boost_INCLUDE_DIRS} ${CMAKE_CURRENT_LIST_DIR}/src ${CMAKE_CURRENT_LIST_DIR}/lib/websocketpp @@ -35,7 +37,7 @@ list(APPEND TARGET_LIBRARIES sioclient) find_package(OpenSSL) if(OPENSSL_FOUND) -add_library(sioclient_tls STATIC ${ALL_SRC}) +add_library(sioclient_tls ${ALL_SRC}) target_include_directories(sioclient_tls PRIVATE ${Boost_INCLUDE_DIRS} ${CMAKE_CURRENT_LIST_DIR}/src ${CMAKE_CURRENT_LIST_DIR}/lib/websocketpp From 646bbe0461eea473dc48fb493b940de90ec49e42 Mon Sep 17 00:00:00 2001 From: Vincent Raman Date: Fri, 4 Sep 2015 19:53:29 +0200 Subject: [PATCH 2/6] Changed ack from message::ptr to message::list --- src/sio_message.h | 13 +++++++++++++ src/sio_socket.cpp | 15 +++++++-------- src/sio_socket.h | 10 +++++----- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/sio_message.h b/src/sio_message.h index 60535235..c9fdd12f 100755 --- a/src/sio_message.h +++ b/src/sio_message.h @@ -291,6 +291,12 @@ namespace sio m_vector(std::move(rhs.m_vector)) { + } + + list & operator= (const message::list && rhs) + { + m_vector = std::move(rhs.m_vector); + return *this; } template @@ -369,6 +375,13 @@ namespace sio return arr; } + message::ptr to_array_message() const + { + message::ptr arr = array_message::create(); + arr->get_vector().insert(arr->get_vector().end(),m_vector.begin(),m_vector.end()); + return arr; + } + private: vector m_vector; }; diff --git a/src/sio_socket.cpp b/src/sio_socket.cpp index 6be373da..b48134e9 100644 --- a/src/sio_socket.cpp +++ b/src/sio_socket.cpp @@ -67,10 +67,10 @@ namespace sio return m_need_ack; } - void event::put_ack_message(message::ptr const& ack_message) + void event::put_ack_message(message::list const& ack_message) { if(m_need_ack) - m_ack_message = ack_message; + m_ack_message = std::move(ack_message); } inline @@ -91,13 +91,13 @@ namespace sio { } - message::ptr const& event::get_ack_message() const + message::list const& event::get_ack_message() const { return m_ack_message; } inline - message::ptr& event::get_ack_message_impl() + message::list& event::get_ack_message_impl() { return m_ack_message; } @@ -155,7 +155,7 @@ namespace sio event_listener get_bind_listener_locked(string const& event); - void ack(int msgId,string const& name,message::ptr const& ack_message); + void ack(int msgId,string const& name,message::list const& ack_message); void timeout_connection(const boost::system::error_code &ec); @@ -449,10 +449,9 @@ namespace sio } } - void socket::impl::ack(int msgId, const string &name, const message::ptr &ack_message) + void socket::impl::ack(int msgId, const string &name, const message::list &ack_message) { - message::list li(ack_message); - packet p(m_nsp, li.to_array_message(name),msgId,true); + packet p(m_nsp, ack_message.to_array_message(),msgId,true); send_packet(p); } diff --git a/src/sio_socket.h b/src/sio_socket.h index c7cc2359..53fa95a8 100644 --- a/src/sio_socket.h +++ b/src/sio_socket.h @@ -19,22 +19,22 @@ namespace sio bool need_ack() const; - void put_ack_message(message::ptr const& ack_message); + void put_ack_message(message::list const& ack_message); - message::ptr const& get_ack_message() const; + message::list const& get_ack_message() const; protected: event(std::string const& nsp,std::string const& name,message::list const& messages,bool need_ack); event(std::string const& nsp,std::string const& name,message::list&& messages,bool need_ack); - message::ptr& get_ack_message_impl(); + message::list& get_ack_message_impl(); private: const std::string m_nsp; const std::string m_name; const message::list m_messages; const bool m_need_ack; - message::ptr m_ack_message; + message::list m_ack_message; friend class event_adapter; }; @@ -46,7 +46,7 @@ namespace sio class socket { public: - typedef std::function event_listener_aux; + typedef std::function event_listener_aux; typedef std::function event_listener; From b0131a43fa7b6739aa0e578c7b2fe893cdc739e3 Mon Sep 17 00:00:00 2001 From: Vincent Raman Date: Fri, 4 Sep 2015 20:40:31 +0200 Subject: [PATCH 3/6] Adapt console example to ack change --- examples/Console/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/Console/main.cpp b/examples/Console/main.cpp index 1dc4e685..846f46fa 100755 --- a/examples/Console/main.cpp +++ b/examples/Console/main.cpp @@ -71,7 +71,7 @@ socket::ptr current_socket; void bind_events(socket::ptr &socket) { - current_socket->on("new message", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::ptr &ack_resp) + current_socket->on("new message", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::list &ack_resp) { _lock.lock(); string user = data->get_map()["username"]->get_string(); @@ -80,7 +80,7 @@ void bind_events(socket::ptr &socket) _lock.unlock(); })); - current_socket->on("user joined",sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::ptr &ack_resp) + current_socket->on("user joined",sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::list &ack_resp) { _lock.lock(); string user = data->get_map()["username"]->get_string(); @@ -91,7 +91,7 @@ void bind_events(socket::ptr &socket) HIGHLIGHT(user<<" joined"<<"\nthere"<<(plural?" are ":"'s ")<< participants<<(plural?" participants":" participant")); _lock.unlock(); })); - current_socket->on("user left", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::ptr &ack_resp) + current_socket->on("user left", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::list &ack_resp) { _lock.lock(); string user = data->get_map()["username"]->get_string(); @@ -126,7 +126,7 @@ MAIN_FUNC getline(cin, nickname); } - current_socket->on("login", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::ptr &ack_resp){ + current_socket->on("login", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::list &ack_resp){ _lock.lock(); participants = data->get_map()["numUsers"]->get_int(); bool plural = participants !=1; From df7638e23ffddac9851d5854f309589afc9406a8 Mon Sep 17 00:00:00 2001 From: Vincent Raman Date: Fri, 4 Sep 2015 20:40:58 +0200 Subject: [PATCH 4/6] Adapt IOS example to ack change --- .../iOS/SioChatDemo/SioChatDemo/CRViewController.mm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/iOS/SioChatDemo/SioChatDemo/CRViewController.mm b/examples/iOS/SioChatDemo/SioChatDemo/CRViewController.mm index 3b45442e..6bac43da 100644 --- a/examples/iOS/SioChatDemo/SioChatDemo/CRViewController.mm +++ b/examples/iOS/SioChatDemo/SioChatDemo/CRViewController.mm @@ -69,7 +69,7 @@ -(void) updateUser:(NSString*)user count:(NSInteger) num joinOrLeft:(BOOL) isJoi using namespace sio; -void OnNewMessage(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bool needACK,sio::message::ptr ackResp) +void OnNewMessage(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bool needACK,sio::message::list ackResp) { if(data->get_flag() == message::flag_object) { @@ -82,7 +82,7 @@ void OnNewMessage(CFTypeRef ctrl,string const& name,sio::message::ptr const& dat } -void OnTyping(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bool needACK,sio::message::ptr ackResp) +void OnTyping(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bool needACK,sio::message::list ackResp) { if(data->get_flag() == message::flag_object) { @@ -93,7 +93,7 @@ void OnTyping(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bo } } -void OnStopTyping(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bool needACK,sio::message::ptr ackResp) +void OnStopTyping(CFTypeRef ctrl,string const& name,sio::message::ptr const& data,bool needACK,sio::message::list ackResp) { if(data->get_flag() == message::flag_object) { @@ -104,7 +104,7 @@ void OnStopTyping(CFTypeRef ctrl,string const& name,sio::message::ptr const& dat } } -void OnUserJoined(CFTypeRef ctrl, string const& name, sio::message::ptr const& data, bool needACK, sio::message::ptr ackResp) +void OnUserJoined(CFTypeRef ctrl, string const& name, sio::message::ptr const& data, bool needACK, sio::message::list ackResp) { if(data->get_flag() == message::flag_object) { @@ -116,7 +116,7 @@ void OnUserJoined(CFTypeRef ctrl, string const& name, sio::message::ptr const& d } } -void OnUserLeft(CFTypeRef ctrl, string const& name, sio::message::ptr const& data, bool needACK, sio::message::ptr ackResp) +void OnUserLeft(CFTypeRef ctrl, string const& name, sio::message::ptr const& data, bool needACK, sio::message::list ackResp) { if(data->get_flag() == message::flag_object) { @@ -129,7 +129,7 @@ void OnUserLeft(CFTypeRef ctrl, string const& name, sio::message::ptr const& dat } -void OnLogin(CFTypeRef ctrl, string const& name, sio::message::ptr const& data, bool needACK, sio::message::ptr ackResp) +void OnLogin(CFTypeRef ctrl, string const& name, sio::message::ptr const& data, bool needACK, sio::message::list ackResp) { if(data->get_flag() == message::flag_object) { From 3500e7b6d2e401ac9f988d860be6b8fb14952163 Mon Sep 17 00:00:00 2001 From: Vincent Raman Date: Fri, 4 Sep 2015 19:54:00 +0200 Subject: [PATCH 5/6] Adapted QT demo to ack change --- examples/QT/SioChatDemo/mainwindow.cpp | 12 ++++++------ examples/QT/SioChatDemo/mainwindow.h | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/QT/SioChatDemo/mainwindow.cpp b/examples/QT/SioChatDemo/mainwindow.cpp index fe7532b4..83a41652 100644 --- a/examples/QT/SioChatDemo/mainwindow.cpp +++ b/examples/QT/SioChatDemo/mainwindow.cpp @@ -137,7 +137,7 @@ void MainWindow::RemoveListItem(QListWidgetItem* item) } -void MainWindow::OnNewMessage(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp) +void MainWindow::OnNewMessage(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp) { if(data->get_flag() == message::flag_object) @@ -152,7 +152,7 @@ void MainWindow::OnNewMessage(std::string const& name,message::ptr const& data,b } } -void MainWindow::OnUserJoined(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp) +void MainWindow::OnUserJoined(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp) { if(data->get_flag() == message::flag_object) { @@ -181,7 +181,7 @@ void MainWindow::OnUserJoined(std::string const& name,message::ptr const& data,b } -void MainWindow::OnUserLeft(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp) +void MainWindow::OnUserLeft(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp) { if(data->get_flag() == message::flag_object) { @@ -209,7 +209,7 @@ void MainWindow::OnUserLeft(std::string const& name,message::ptr const& data,boo } } -void MainWindow::OnTyping(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp) +void MainWindow::OnTyping(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp) { if(m_typingItem == NULL) { @@ -223,7 +223,7 @@ void MainWindow::OnTyping(std::string const& name,message::ptr const& data,bool } } -void MainWindow::OnStopTyping(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp) +void MainWindow::OnStopTyping(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp) { if(m_typingItem != NULL) { @@ -232,7 +232,7 @@ void MainWindow::OnStopTyping(std::string const& name,message::ptr const& data,b } } -void MainWindow::OnLogin(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp) +void MainWindow::OnLogin(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp) { Q_EMIT RequestToggleInputs(true); int numUser = data->get_map()["numUsers"]->get_int(); diff --git a/examples/QT/SioChatDemo/mainwindow.h b/examples/QT/SioChatDemo/mainwindow.h index 49147add..df32afe8 100644 --- a/examples/QT/SioChatDemo/mainwindow.h +++ b/examples/QT/SioChatDemo/mainwindow.h @@ -41,12 +41,12 @@ private Q_SLOTS: void NicknameAccept(); void NicknameCancelled(); private: - void OnNewMessage(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp); - void OnUserJoined(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp); - void OnUserLeft(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp); - void OnTyping(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp); - void OnStopTyping(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp); - void OnLogin(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp); + void OnNewMessage(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp); + void OnUserJoined(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp); + void OnUserLeft(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp); + void OnTyping(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp); + void OnStopTyping(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp); + void OnLogin(std::string const& name,message::ptr const& data,bool hasAck,message::list &ack_resp); void OnConnected(std::string const& nsp); void OnClosed(client::close_reason const& reason); void OnFailed(); From 7dc236e160a12ae946f1e6a8acc3b204297ac7f7 Mon Sep 17 00:00:00 2001 From: Vincent Raman Date: Sun, 6 Sep 2015 00:49:54 +0200 Subject: [PATCH 6/6] Proper soname for dynamic libraries --- CMakeLists.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e671da66..8c2fad3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,10 @@ PROJECT(sioclient) option(BUILD_SHARED_LIBS "Build the shared library" OFF) option(Boost_USE_STATIC_LIBS "Use Boost static version" ON) +set(MAJOR 1) +set(MINOR 6) +set(PATCH 0) + if(NOT CMAKE_BUILD_TYPE ) MESSAGE(STATUS "not define build type, set to release" ) set(CMAKE_BUILD_TYPE Release ) @@ -33,6 +37,13 @@ target_include_directories(sioclient PRIVATE ${Boost_INCLUDE_DIRS} set_property(TARGET sioclient PROPERTY CXX_STANDARD 11) set_property(TARGET sioclient PROPERTY CXX_STANDARD_REQUIRED ON) target_link_libraries(sioclient PRIVATE ${Boost_LIBRARIES}) +if(BUILD_SHARED_LIBS) +set_target_properties(sioclient + PROPERTIES + SOVERSION ${MAJOR} + VERSION ${MAJOR}.${MINOR}.${PATCH} + ) +endif() list(APPEND TARGET_LIBRARIES sioclient) find_package(OpenSSL) @@ -49,6 +60,13 @@ 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 ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ) target_compile_definitions(sioclient_tls PRIVATE -DSIO_TLS) +if(BUILD_SHARED_LIBS) +set_target_properties(sioclient_tls + PROPERTIES + SOVERSION ${MAJOR} + VERSION ${MAJOR}.${MINOR}.${PATCH} + ) +endif() list(APPEND TARGET_LIBRARIES sioclient_tls) endif()