Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
melode11 committed Sep 20, 2015
2 parents 3d0ac44 + 3aee49c commit f02dc68
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 38 deletions.
26 changes: 23 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 )
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions examples/Console/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions examples/QT/SioChatDemo/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions examples/QT/SioChatDemo/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions examples/iOS/SioChatDemo/SioChatDemo/CRViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down
13 changes: 13 additions & 0 deletions src/sio_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
Expand Down Expand Up @@ -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<message::ptr> m_vector;
};
Expand Down
15 changes: 7 additions & 8 deletions src/sio_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}

Expand Down
10 changes: 5 additions & 5 deletions src/sio_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -46,7 +46,7 @@ namespace sio
class socket
{
public:
typedef std::function<void(const std::string& name,message::ptr const& message,bool need_ack, message::ptr& ack_message)> event_listener_aux;
typedef std::function<void(const std::string& name,message::ptr const& message,bool need_ack, message::list& ack_message)> event_listener_aux;

typedef std::function<void(event& event)> event_listener;

Expand Down

0 comments on commit f02dc68

Please sign in to comment.