Skip to content

Commit

Permalink
add null message type, fix crash when null message cames
Browse files Browse the repository at this point in the history
  • Loading branch information
melode11 committed Sep 20, 2015
1 parent bbbc1e3 commit 3d0ac44
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/internal/sio_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ namespace sio
val.SetBool(msg.get_bool());
}

void accept_null_message(Value& val)
{
val.SetNull();
}

void accept_int_message(int_message const& msg, Value& val)
{
val.SetInt64(msg.get_int());
Expand Down Expand Up @@ -105,6 +110,11 @@ namespace sio
accept_bool_message(*(static_cast<const bool_message*>(msg_ptr)), val);
break;
}
case message::flag_null:
{
accept_null_message(val);
break;
}
case message::flag_binary:
{
accept_binary_message(*(static_cast<const binary_message*>(msg_ptr)), val,doc,buffers);
Expand Down Expand Up @@ -177,6 +187,10 @@ namespace sio
{
return bool_message::create(value.GetBool());
}
else if(value.IsNull())
{
return null_message::create();
}
return message::ptr();
}

Expand Down
18 changes: 17 additions & 1 deletion src/sio_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace sio
flag_binary,
flag_array,
flag_object,
flag_boolean
flag_boolean,
flag_null
};

virtual ~message(){};
Expand Down Expand Up @@ -113,6 +114,21 @@ namespace sio
message(flag f):_flag(f){}
};

class null_message : public message
{
protected:
null_message()
:message(flag_null)
{
}

public:
static message::ptr create()
{
return ptr(new null_message());
}
};

class bool_message : public message
{
bool _v;
Expand Down

0 comments on commit 3d0ac44

Please sign in to comment.