diff --git a/src/sio_message.h b/src/sio_message.h index e0166db9..b635380e 100755 --- a/src/sio_message.h +++ b/src/sio_message.h @@ -11,6 +11,7 @@ #include #include #include +#include namespace sio { using namespace std; @@ -28,7 +29,7 @@ namespace sio flag_object }; - virtual ~message() = default; + virtual ~message(){}; class list; @@ -261,6 +262,13 @@ namespace sio m_vector(std::move(rhs.m_vector)) { + } + + template + list(T&& content, + typename enable_if,typename remove_reference::type>::value>::type* = 0): + m_vector(std::forward(content)) + { } list(message::list const& rhs): diff --git a/src/sio_socket.cpp b/src/sio_socket.cpp index 754299ec..3dd53dd9 100644 --- a/src/sio_socket.cpp +++ b/src/sio_socket.cpp @@ -131,7 +131,7 @@ namespace sio void close(); - void emit(std::string const& name, message::list const& msglist, std::function const& ack); + void emit(std::string const& name, message::list const& msglist, std::function const& ack); std::string const& get_namespace() const {return m_nsp;} @@ -150,7 +150,7 @@ namespace sio // Message Parsing callbacks. void on_socketio_event(const std::string& nsp, int msgId,const std::string& name, message::list&& message); - void on_socketio_ack(int msgId, message::ptr const& message); + void on_socketio_ack(int msgId, message::list const& message); void on_socketio_error(message::ptr const& err_message); event_listener get_bind_listener_locked(string const& event); @@ -172,7 +172,7 @@ namespace sio bool m_connected; std::string m_nsp; - std::map > m_acks; + std::map > m_acks; std::map m_event_binding; @@ -243,7 +243,7 @@ namespace sio unsigned int socket::impl::s_global_event_id = 1; - void socket::impl::emit(std::string const& name, message::list const& msglist, std::function const& ack) + void socket::impl::emit(std::string const& name, message::list const& msglist, std::function const& ack) { NULL_GUARD(m_client); message::ptr msg_ptr = msglist.to_array_message(name); @@ -398,19 +398,13 @@ namespace sio const message::ptr ptr = p.get_message(); if(ptr->get_flag() == message::flag_array) { - const array_message* array_ptr = static_cast(ptr.get()); - if(array_ptr->get_vector().size() >= 1&&array_ptr->get_vector()[0]->get_flag() == message::flag_string) - { - message::ptr value_ptr; - if(array_ptr->get_vector().size()>1) - { - value_ptr = array_ptr->get_vector()[1]; - } - this->on_socketio_ack(p.get_pack_id(), value_ptr); - break; - } + message::list msglist(ptr->get_vector()); + this->on_socketio_ack(p.get_pack_id(),msglist); } - this->on_socketio_ack(p.get_pack_id(),ptr); + else + { + this->on_socketio_ack(p.get_pack_id(),message::list(ptr)); + } break; } // Error @@ -445,9 +439,9 @@ namespace sio send_packet(p); } - void socket::impl::on_socketio_ack(int msgId, message::ptr const& message) + void socket::impl::on_socketio_ack(int msgId, message::list const& message) { - std::function l; + std::function l; { std::lock_guard guard(m_event_mutex); auto it = m_acks.find(msgId); @@ -551,7 +545,7 @@ namespace sio m_impl->off_error(); } - void socket::emit(std::string const& name, message::list const& msglist, std::function const& ack) + void socket::emit(std::string const& name, message::list const& msglist, std::function const& ack) { m_impl->emit(name, msglist,ack); } diff --git a/src/sio_socket.h b/src/sio_socket.h index a509c957..c7cc2359 100644 --- a/src/sio_socket.h +++ b/src/sio_socket.h @@ -70,7 +70,7 @@ namespace sio void off_error(); - void emit(std::string const& name, message::list const& msglist = nullptr, std::function const& ack = nullptr); + void emit(std::string const& name, message::list const& msglist = nullptr, std::function const& ack = nullptr); std::string const& get_namespace() const;