Skip to content

Commit

Permalink
breaking change of ack callback, windows compile fix for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
melode11 committed Jun 15, 2015
1 parent 9e9d76c commit 7a3933e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
10 changes: 9 additions & 1 deletion src/sio_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vector>
#include <map>
#include <cassert>
#include <type_traits>
namespace sio
{
using namespace std;
Expand All @@ -28,7 +29,7 @@ namespace sio
flag_object
};

virtual ~message() = default;
virtual ~message(){};

class list;

Expand Down Expand Up @@ -261,6 +262,13 @@ namespace sio
m_vector(std::move(rhs.m_vector))
{

}

template <typename T>
list(T&& content,
typename enable_if<is_same<vector<message::ptr>,typename remove_reference<T>::type>::value>::type* = 0):
m_vector(std::forward<T>(content))
{
}

list(message::list const& rhs):
Expand Down
32 changes: 13 additions & 19 deletions src/sio_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace sio

void close();

void emit(std::string const& name, message::list const& msglist, std::function<void (message::ptr const&)> const& ack);
void emit(std::string const& name, message::list const& msglist, std::function<void (message::list const&)> const& ack);

std::string const& get_namespace() const {return m_nsp;}

Expand All @@ -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);
Expand All @@ -172,7 +172,7 @@ namespace sio
bool m_connected;
std::string m_nsp;

std::map<unsigned int, std::function<void (message::ptr const&)> > m_acks;
std::map<unsigned int, std::function<void (message::list const&)> > m_acks;

std::map<std::string, event_listener> m_event_binding;

Expand Down Expand Up @@ -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<void (message::ptr const&)> const& ack)
void socket::impl::emit(std::string const& name, message::list const& msglist, std::function<void (message::list const&)> const& ack)
{
NULL_GUARD(m_client);
message::ptr msg_ptr = msglist.to_array_message(name);
Expand Down Expand Up @@ -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<const array_message*>(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
Expand Down Expand Up @@ -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<void (message::ptr const&)> l;
std::function<void (message::list const&)> l;
{
std::lock_guard<std::mutex> guard(m_event_mutex);
auto it = m_acks.find(msgId);
Expand Down Expand Up @@ -551,7 +545,7 @@ namespace sio
m_impl->off_error();
}

void socket::emit(std::string const& name, message::list const& msglist, std::function<void (message::ptr const&)> const& ack)
void socket::emit(std::string const& name, message::list const& msglist, std::function<void (message::list const&)> const& ack)
{
m_impl->emit(name, msglist,ack);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sio_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace sio

void off_error();

void emit(std::string const& name, message::list const& msglist = nullptr, std::function<void (message::ptr const&)> const& ack = nullptr);
void emit(std::string const& name, message::list const& msglist = nullptr, std::function<void (message::list const&)> const& ack = nullptr);

std::string const& get_namespace() const;

Expand Down

0 comments on commit 7a3933e

Please sign in to comment.