Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
f2d26fdf
Commit
f2d26fdf
authored
Jul 25, 2016
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use unsigned integers in protobuf example
parent
5929d5d5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
examples/broker/protobuf_broker.cpp
examples/broker/protobuf_broker.cpp
+7
-7
No files found.
examples/broker/protobuf_broker.cpp
View file @
f2d26fdf
...
@@ -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
<
u
int32_t
>
(
buf
.
size
()));
self
->
write
(
hdl
,
sizeof
(
int32_t
),
&
s
);
self
->
write
(
hdl
,
sizeof
(
u
int32_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
(
u
int32_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
;
u
int32_t
num_bytes
;
memcpy
(
&
num_bytes
,
msg
.
buf
.
data
(),
sizeof
(
int32_t
));
memcpy
(
&
num_bytes
,
msg
.
buf
.
data
(),
sizeof
(
u
int32_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
(
u
int32_t
)));
self
->
become
(
await_length_prefix
);
self
->
become
(
await_length_prefix
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment