diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b704043..8c2fad3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,13 @@ 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) + +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 ) @@ -11,7 +18,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 +27,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 @@ -31,11 +37,18 @@ 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) 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 @@ -47,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() 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; 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(); 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) { diff --git a/src/sio_message.h b/src/sio_message.h index 6aaa6956..17ba2ad1 100755 --- a/src/sio_message.h +++ b/src/sio_message.h @@ -307,6 +307,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 @@ -385,6 +391,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;