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
44de1c92
Commit
44de1c92
authored
Feb 17, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix false warning when using response promises
parent
0c4ebcfe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
40 deletions
+42
-40
libcaf_core/caf/policy/invoke_policy.hpp
libcaf_core/caf/policy/invoke_policy.hpp
+42
-40
No files found.
libcaf_core/caf/policy/invoke_policy.hpp
View file @
44de1c92
...
...
@@ -174,50 +174,52 @@ class invoke_policy {
if
(
res
->
empty
())
{
// make sure synchronous requests always receive a response;
// note: !current_element() means client has forwarded the request
if
(
self
->
current_element
()
&&
mid
.
is_request
()
&&
!
mid
.
is_answered
())
{
CAF_LOG_WARNING
(
"actor with ID "
<<
self
->
id
()
<<
" did not reply to a synchronous request message"
);
auto
fhdl
=
fetch_response_promise
(
self
,
hdl
);
if
(
fhdl
)
{
fhdl
.
deliver
(
make_message
(
unit
));
}
}
}
else
{
CAF_LOGF_DEBUG
(
"res = "
<<
to_string
(
*
res
));
if
(
res
->
size
()
==
2
&&
res
->
match_element
(
0
,
detail
::
type_nr
<
atom_value
>::
value
,
nullptr
)
&&
res
->
match_element
(
1
,
detail
::
type_nr
<
uint64_t
>::
value
,
nullptr
)
&&
res
->
template
get_as
<
atom_value
>(
0
)
==
atom
(
"MESSAGE_ID"
))
{
CAF_LOG_DEBUG
(
"message handler returned a message id wrapper"
);
auto
id
=
res
->
template
get_as
<
uint64_t
>(
1
);
auto
msg_id
=
message_id
::
from_integer_value
(
id
);
auto
ref_opt
=
self
->
sync_handler
(
msg_id
);
// install a behavior that calls the user-defined behavior
// and using the result of its inner behavior as response
if
(
ref_opt
)
{
auto
&
ptr
=
self
->
current_element
();
if
(
ptr
)
{
mid
=
ptr
->
mid
;
if
(
mid
.
is_request
()
&&
!
mid
.
is_answered
())
{
CAF_LOG_WARNING
(
"actor with ID "
<<
self
->
id
()
<<
" did not reply to a synchronous request message"
);
auto
fhdl
=
fetch_response_promise
(
self
,
hdl
);
behavior
inner
=
*
ref_opt
;
ref_opt
->
assign
(
others
()
>>
[
=
]
{
// inner is const inside this lambda and mutable a C++14 feature
behavior
cpy
=
inner
;
auto
inner_res
=
cpy
(
self
->
last_dequeued
());
if
(
inner_res
)
{
fhdl
.
deliver
(
*
inner_res
);
}
}
);
if
(
fhdl
)
{
fhdl
.
deliver
(
make_message
(
unit
));
}
}
}
else
{
// respond by using the result of 'fun'
CAF_LOG_DEBUG
(
"respond via response_promise"
);
}
return
res
;
}
CAF_LOGF_DEBUG
(
"res = "
<<
to_string
(
*
res
));
if
(
res
->
template
match_elements
<
atom_value
,
uint64_t
>()
&&
res
->
template
get_as
<
atom_value
>(
0
)
==
atom
(
"MESSAGE_ID"
))
{
CAF_LOG_DEBUG
(
"message handler returned a message id wrapper"
);
auto
id
=
res
->
template
get_as
<
uint64_t
>(
1
);
auto
msg_id
=
message_id
::
from_integer_value
(
id
);
auto
ref_opt
=
self
->
sync_handler
(
msg_id
);
// install a behavior that calls the user-defined behavior
// and using the result of its inner behavior as response
if
(
ref_opt
)
{
auto
fhdl
=
fetch_response_promise
(
self
,
hdl
);
if
(
fhdl
)
{
fhdl
.
deliver
(
std
::
move
(
*
res
));
// inform caller about success
return
message
{};
}
behavior
inner
=
*
ref_opt
;
ref_opt
->
assign
(
others
()
>>
[
=
]
{
// inner is const inside this lambda and mutable a C++14 feature
behavior
cpy
=
inner
;
auto
inner_res
=
cpy
(
self
->
last_dequeued
());
if
(
inner_res
)
{
fhdl
.
deliver
(
*
inner_res
);
}
}
);
}
return
res
;
}
// respond by using the result of 'fun'
CAF_LOG_DEBUG
(
"respond via response_promise"
);
auto
fhdl
=
fetch_response_promise
(
self
,
hdl
);
if
(
fhdl
)
{
fhdl
.
deliver
(
std
::
move
(
*
res
));
// inform caller about success by returning not none
return
message
{};
}
return
res
;
}
...
...
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