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
9d7204e5
Commit
9d7204e5
authored
Feb 25, 2015
by
Marian Triebe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update protobuf example to use `or_else` API
parent
d36dc898
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
13 deletions
+11
-13
examples/brokers/protobuf_broker.cpp
examples/brokers/protobuf_broker.cpp
+11
-13
No files found.
examples/brokers/protobuf_broker.cpp
View file @
9d7204e5
...
...
@@ -79,11 +79,11 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) {
self
->
quit
(
dm
.
reason
);
}
},
others
()
>>
[
=
]
{
cout
<<
"unexpected: "
<<
to_string
(
self
->
last_dequeued
())
<<
endl
;
others
>>
[
=
]
{
cout
<<
"unexpected: "
<<
to_string
(
self
->
current_message
())
<<
endl
;
}
};
message_handler
await_protobuf_data
{
auto
await_protobuf_data
=
message_handler
{
[
=
](
const
new_data_msg
&
msg
)
{
org
::
libcppa
::
PingOrPong
p
;
p
.
ParseFromArray
(
msg
.
buf
.
data
(),
static_cast
<
int
>
(
msg
.
buf
.
size
()));
...
...
@@ -100,10 +100,9 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) {
// receive next length prefix
self
->
configure_read
(
hdl
,
receive_policy
::
exactly
(
sizeof
(
int32_t
)));
self
->
unbecome
();
},
default_bhvr
};
message_handler
await_length_prefix
{
}
}.
or_else
(
default_bhvr
);
auto
await_length_prefix
=
message_handler
{
[
=
](
const
new_data_msg
&
msg
)
{
int32_t
num_bytes
;
memcpy
(
&
num_bytes
,
msg
.
buf
.
data
(),
sizeof
(
int32_t
));
...
...
@@ -117,9 +116,8 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) {
auto
nb
=
static_cast
<
size_t
>
(
num_bytes
);
self
->
configure_read
(
hdl
,
receive_policy
::
exactly
(
nb
));
self
->
become
(
keep_behavior
,
await_protobuf_data
);
},
default_bhvr
};
}
}.
or_else
(
default_bhvr
);
// initial setup
self
->
configure_read
(
hdl
,
receive_policy
::
exactly
(
sizeof
(
int32_t
)));
self
->
become
(
await_length_prefix
);
...
...
@@ -135,8 +133,8 @@ behavior server(broker* self, actor buddy) {
// only accept 1 connection in our example
self
->
quit
();
},
others
()
>>
[
=
]
{
cout
<<
"unexpected: "
<<
to_string
(
self
->
last_dequeued
())
<<
endl
;
others
>>
[
=
]
{
cout
<<
"unexpected: "
<<
to_string
(
self
->
current_message
())
<<
endl
;
}
};
}
...
...
@@ -161,7 +159,7 @@ int main(int argc, char** argv) {
print_on_exit
(
ping_actor
,
"ping"
);
send_as
(
io_actor
,
ping_actor
,
atom
(
"kickoff"
),
io_actor
);
},
others
()
>>
[]
{
others
>>
[]
{
cerr
<<
"use with eihter '-s PORT' as server or "
"'-c HOST PORT' as client"
<<
endl
;
...
...
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