Commit f2d26fdf authored by Dominik Charousset's avatar Dominik Charousset

Use unsigned integers in protobuf example

parent 5929d5d5
...@@ -73,8 +73,8 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) { ...@@ -73,8 +73,8 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) {
}); });
auto write = [=](const org::libcppa::PingOrPong& p) { auto write = [=](const org::libcppa::PingOrPong& p) {
string buf = p.SerializeAsString(); string buf = p.SerializeAsString();
int32_t s = htonl(static_cast<int32_t>(buf.size())); auto s = htonl(static_cast<uint32_t>(buf.size()));
self->write(hdl, sizeof(int32_t), &s); self->write(hdl, sizeof(uint32_t), &s);
self->write(hdl, buf.size(), buf.data()); self->write(hdl, buf.size(), buf.data());
self->flush(hdl); self->flush(hdl);
}; };
...@@ -112,16 +112,16 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) { ...@@ -112,16 +112,16 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) {
cerr << "neither Ping nor Pong!" << endl; cerr << "neither Ping nor Pong!" << endl;
} }
// receive next length prefix // receive next length prefix
self->configure_read(hdl, receive_policy::exactly(sizeof(int32_t))); self->configure_read(hdl, receive_policy::exactly(sizeof(uint32_t)));
self->unbecome(); self->unbecome();
} }
}.or_else(default_bhvr); }.or_else(default_bhvr);
auto await_length_prefix = message_handler { auto await_length_prefix = message_handler {
[=](const new_data_msg& msg) { [=](const new_data_msg& msg) {
int32_t num_bytes; uint32_t num_bytes;
memcpy(&num_bytes, msg.buf.data(), sizeof(int32_t)); memcpy(&num_bytes, msg.buf.data(), sizeof(uint32_t));
num_bytes = htonl(num_bytes); num_bytes = htonl(num_bytes);
if (num_bytes < 0 || num_bytes > (1024 * 1024)) { if (num_bytes > (1024 * 1024)) {
aout(self) << "someone is trying something nasty" << endl; aout(self) << "someone is trying something nasty" << endl;
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
return; return;
...@@ -133,7 +133,7 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) { ...@@ -133,7 +133,7 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) {
} }
}.or_else(default_bhvr); }.or_else(default_bhvr);
// initial setup // initial setup
self->configure_read(hdl, receive_policy::exactly(sizeof(int32_t))); self->configure_read(hdl, receive_policy::exactly(sizeof(uint32_t)));
self->become(await_length_prefix); self->become(await_length_prefix);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment