From 646bbe0461eea473dc48fb493b940de90ec49e42 Mon Sep 17 00:00:00 2001 From: Vincent Raman Date: Fri, 4 Sep 2015 19:53:29 +0200 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 4/4] 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();