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
962d1439
Commit
962d1439
authored
Feb 10, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-implement mailbox_element as simple struct
parent
ddfd8def
Changes
28
Show whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
126 additions
and
361 deletions
+126
-361
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+0
-1
libcaf_core/caf/actor_pool.hpp
libcaf_core/caf/actor_pool.hpp
+3
-3
libcaf_core/caf/catch_all.hpp
libcaf_core/caf/catch_all.hpp
+2
-3
libcaf_core/caf/detail/blocking_behavior.hpp
libcaf_core/caf/detail/blocking_behavior.hpp
+3
-3
libcaf_core/caf/detail/split_join.hpp
libcaf_core/caf/detail/split_join.hpp
+2
-4
libcaf_core/caf/function_view.hpp
libcaf_core/caf/function_view.hpp
+2
-2
libcaf_core/caf/fwd.hpp
libcaf_core/caf/fwd.hpp
+1
-1
libcaf_core/caf/mailbox_element.hpp
libcaf_core/caf/mailbox_element.hpp
+22
-119
libcaf_core/caf/message_view.hpp
libcaf_core/caf/message_view.hpp
+0
-41
libcaf_core/caf/scheduled_actor.hpp
libcaf_core/caf/scheduled_actor.hpp
+5
-5
libcaf_core/caf/skip.hpp
libcaf_core/caf/skip.hpp
+2
-3
libcaf_core/src/actor_pool.cpp
libcaf_core/src/actor_pool.cpp
+4
-6
libcaf_core/src/blocking_actor.cpp
libcaf_core/src/blocking_actor.cpp
+4
-5
libcaf_core/src/decorator/splitter.cpp
libcaf_core/src/decorator/splitter.cpp
+1
-2
libcaf_core/src/detail/blocking_behavior.cpp
libcaf_core/src/detail/blocking_behavior.cpp
+1
-1
libcaf_core/src/forwarding_actor_proxy.cpp
libcaf_core/src/forwarding_actor_proxy.cpp
+2
-2
libcaf_core/src/group_manager.cpp
libcaf_core/src/group_manager.cpp
+5
-5
libcaf_core/src/mailbox_element.cpp
libcaf_core/src/mailbox_element.cpp
+34
-54
libcaf_core/src/message_view.cpp
libcaf_core/src/message_view.cpp
+0
-27
libcaf_core/src/raw_event_based_actor.cpp
libcaf_core/src/raw_event_based_actor.cpp
+3
-3
libcaf_core/src/scheduled_actor.cpp
libcaf_core/src/scheduled_actor.cpp
+13
-13
libcaf_core/src/skip.cpp
libcaf_core/src/skip.cpp
+1
-1
libcaf_core/test/blocking_actor.cpp
libcaf_core/test/blocking_actor.cpp
+2
-2
libcaf_core/test/broadcast_downstream_manager.cpp
libcaf_core/test/broadcast_downstream_manager.cpp
+1
-1
libcaf_core/test/mailbox_element.cpp
libcaf_core/test/mailbox_element.cpp
+0
-40
libcaf_io/caf/io/broker_servant.hpp
libcaf_io/caf/io/broker_servant.hpp
+7
-6
libcaf_io/src/io/datagram_servant.cpp
libcaf_io/src/io/datagram_servant.cpp
+3
-4
libcaf_io/src/io/scribe.cpp
libcaf_io/src/io/scribe.cpp
+3
-4
No files found.
libcaf_core/CMakeLists.txt
View file @
962d1439
...
...
@@ -117,7 +117,6 @@ set(CAF_CORE_SOURCES
src/message_builder.cpp
src/message_handler.cpp
src/message_priority_strings.cpp
src/message_view.cpp
src/monitorable_actor.cpp
src/node_id.cpp
src/outbound_path.cpp
...
...
libcaf_core/caf/actor_pool.hpp
View file @
962d1439
...
...
@@ -109,9 +109,9 @@ protected:
void
on_cleanup
(
const
error
&
reason
)
override
;
private:
bool
filter
(
upgrade_lock
<
detail
::
shared_spinlock
>&
,
const
strong_actor_ptr
&
sender
,
message_id
mid
,
message_view
&
mv
,
execution_unit
*
eu
);
bool
filter
(
upgrade_lock
<
detail
::
shared_spinlock
>&
,
const
strong_actor_ptr
&
sender
,
message_id
mid
,
message
&
msg
,
execution_unit
*
eu
);
// call without workers_mtx_ held
void
quit
(
execution_unit
*
host
);
...
...
libcaf_core/caf/catch_all.hpp
View file @
962d1439
...
...
@@ -22,14 +22,13 @@
#include <type_traits>
#include "caf/message.hpp"
#include "caf/message_view.hpp"
#include "caf/result.hpp"
namespace
caf
{
template
<
class
F
>
struct
catch_all
{
using
fun_type
=
std
::
function
<
result
<
message
>
(
message
_view
&
)
>
;
using
fun_type
=
std
::
function
<
result
<
message
>
(
message
&
)
>
;
F
handler
;
...
...
@@ -44,7 +43,7 @@ struct catch_all {
static_assert
(
std
::
is_convertible
<
F
,
fun_type
>::
value
,
"catch-all handler must have signature "
"result<message> (message
_view
&)"
);
"result<message> (message&)"
);
fun_type
lift
()
const
{
return
handler
;
...
...
libcaf_core/caf/detail/blocking_behavior.hpp
View file @
962d1439
...
...
@@ -35,7 +35,7 @@ public:
virtual
~
blocking_behavior
();
virtual
result
<
message
>
fallback
(
message
_view
&
);
virtual
result
<
message
>
fallback
(
message
&
);
virtual
timespan
timeout
();
...
...
@@ -54,7 +54,7 @@ public:
blocking_behavior_v2
(
blocking_behavior_v2
&&
)
=
default
;
result
<
message
>
fallback
(
message
_view
&
x
)
override
{
result
<
message
>
fallback
(
message
&
x
)
override
{
return
f
.
handler
(
x
);
}
};
...
...
@@ -93,7 +93,7 @@ public:
blocking_behavior_v4
(
blocking_behavior_v4
&&
)
=
default
;
result
<
message
>
fallback
(
message
_view
&
x
)
override
{
result
<
message
>
fallback
(
message
&
x
)
override
{
return
f1
.
handler
(
x
);
}
...
...
libcaf_core/caf/detail/split_join.hpp
View file @
962d1439
...
...
@@ -46,15 +46,13 @@ public:
}
behavior
make_behavior
()
override
{
auto
f
=
[
=
](
scheduled_actor
*
,
message_view
&
xs
)
->
result
<
message
>
{
auto
msg
=
xs
.
move_content_to_message
();
auto
f
=
[
=
](
scheduled_actor
*
,
message
&
msg
)
->
result
<
message
>
{
auto
rp
=
this
->
make_response_promise
();
split_
(
workset_
,
msg
);
for
(
auto
&
x
:
workset_
)
this
->
send
(
x
.
first
,
std
::
move
(
x
.
second
));
auto
g
=
[
=
](
scheduled_actor
*
,
message_view
&
ys
)
mutable
->
result
<
message
>
{
auto
res
=
ys
.
move_content_to_message
();
=
[
=
](
scheduled_actor
*
,
message
&
res
)
mutable
->
result
<
message
>
{
join_
(
value_
,
res
);
if
(
--
awaited_results_
==
0
)
{
rp
.
deliver
(
value_
);
...
...
libcaf_core/caf/function_view.hpp
View file @
962d1439
...
...
@@ -87,8 +87,8 @@ struct CAF_CORE_EXPORT function_view_storage_catch_all {
// nop
}
result
<
message
>
operator
()(
message
_view
&
xs
)
{
*
storage_
=
xs
.
move_content_to_message
(
);
result
<
message
>
operator
()(
message
&
msg
)
{
*
storage_
=
std
::
move
(
msg
);
return
message
{};
}
};
...
...
libcaf_core/caf/fwd.hpp
View file @
962d1439
...
...
@@ -307,7 +307,7 @@ using stream_manager_ptr = intrusive_ptr<stream_manager>;
// -- unique pointer aliases ---------------------------------------------------
using
mailbox_element_ptr
=
std
::
unique_ptr
<
mailbox_element
,
detail
::
disposer
>
;
using
mailbox_element_ptr
=
std
::
unique_ptr
<
mailbox_element
>
;
using
tracing_data_ptr
=
std
::
unique_ptr
<
tracing_data
>
;
using
type_erased_value_ptr
=
std
::
unique_ptr
<
type_erased_value
>
;
...
...
libcaf_core/caf/mailbox_element.hpp
View file @
962d1439
...
...
@@ -33,7 +33,6 @@
#include "caf/memory_managed.hpp"
#include "caf/message.hpp"
#include "caf/message_id.hpp"
#include "caf/message_view.hpp"
#include "caf/meta/omittable_if_empty.hpp"
#include "caf/meta/type_name.hpp"
#include "caf/ref_counted.hpp"
...
...
@@ -43,9 +42,7 @@
namespace
caf
{
class
CAF_CORE_EXPORT
mailbox_element
:
public
intrusive
::
singly_linked
<
mailbox_element
>
,
public
memory_managed
,
public
message_view
{
:
public
intrusive
::
singly_linked
<
mailbox_element
>
{
public:
using
forwarding_stack
=
std
::
vector
<
strong_actor_ptr
>
;
...
...
@@ -66,13 +63,15 @@ public:
tracing_data_ptr
tracing_id
;
#endif // CAF_ENABLE_ACTOR_PROFILER
mailbox_element
();
/// Stores the payload.
message
payload
;
mailbox_element
(
strong_actor_ptr
&&
x
,
message_id
y
,
forwarding_stack
&&
z
)
;
mailbox_element
(
)
=
default
;
~
mailbox_element
()
override
;
mailbox_element
(
strong_actor_ptr
sender
,
message_id
mid
,
forwarding_stack
stages
,
message
payload
);
inline
bool
is_high_priority
()
const
{
bool
is_high_priority
()
const
{
return
mid
.
category
()
==
message_id
::
urgent_message_category
;
}
...
...
@@ -80,31 +79,19 @@ public:
mailbox_element
(
const
mailbox_element
&
)
=
delete
;
mailbox_element
&
operator
=
(
mailbox_element
&&
)
=
delete
;
mailbox_element
&
operator
=
(
const
mailbox_element
&
)
=
delete
;
};
/// Corrects the message ID for down- and upstream messages to make sure the
/// category for a `mailbox_element` matches its content.
template
<
class
...
>
struct
mailbox_category_corrector
{
static
constexpr
message_id
apply
(
message_id
x
)
noexcept
{
return
x
;
}
};
// -- backward compatibility -------------------------------------------------
template
<
>
struct
mailbox_category_corrector
<
downstream_msg
>
{
static
constexpr
message_id
apply
(
message_id
x
)
noexcept
{
return
x
.
with_category
(
message_id
::
downstream_message_category
);
message
&
content
()
noexcept
{
return
payload
;
}
};
template
<
>
struct
mailbox_category_corrector
<
upstream_msg
>
{
static
constexpr
message_id
apply
(
message_id
x
)
noexcept
{
return
x
.
with_category
(
message_id
::
upstream_message_category
);
const
message
&
content
()
const
noexcept
{
return
payload
;
}
};
/// @relates mailbox_element
template
<
class
Inspector
>
typename
Inspector
::
result_type
inspect
(
Inspector
&
f
,
mailbox_element
&
x
)
{
...
...
@@ -113,112 +100,28 @@ typename Inspector::result_type inspect(Inspector& f, mailbox_element& x) {
#ifdef CAF_ENABLE_ACTOR_PROFILER
x
.
tracing_id
,
#endif // CAF_ENABLE_ACTOR_PROFILER
x
.
content
()
);
x
.
payload
);
}
/// Encapsulates arbitrary data in a message element.
template
<
class
...
Ts
>
class
mailbox_element_vals
final
:
public
mailbox_element
,
public
detail
::
tuple_vals_impl
<
type_erased_tuple
,
Ts
...
>
{
public:
template
<
class
...
Us
>
mailbox_element_vals
(
strong_actor_ptr
&&
x0
,
message_id
x1
,
forwarding_stack
&&
x2
,
Us
&&
...
xs
)
:
mailbox_element
(
std
::
move
(
x0
),
mailbox_category_corrector
<
Ts
...
>::
apply
(
x1
),
std
::
move
(
x2
)),
detail
::
tuple_vals_impl
<
type_erased_tuple
,
Ts
...
>
(
std
::
forward
<
Us
>
(
xs
)...)
{
// nop
}
type_erased_tuple
&
content
()
override
{
return
*
this
;
}
const
type_erased_tuple
&
content
()
const
override
{
return
*
this
;
}
message
move_content_to_message
()
override
{
message_factory
f
;
auto
&
xs
=
this
->
data
();
return
detail
::
apply_moved_args
(
f
,
detail
::
get_indices
(
xs
),
xs
);
}
message
copy_content_to_message
()
const
override
{
message_factory
f
;
auto
&
xs
=
this
->
data
();
return
detail
::
apply_args
(
f
,
detail
::
get_indices
(
xs
),
xs
);
}
void
dispose
()
noexcept
{
this
->
deref
();
}
};
/// Provides a view for treating arbitrary data as message element.
template
<
class
...
Ts
>
class
mailbox_element_view
final
:
public
mailbox_element
,
public
detail
::
type_erased_tuple_view
<
Ts
...
>
{
public:
mailbox_element_view
(
strong_actor_ptr
&&
x0
,
message_id
x1
,
forwarding_stack
&&
x2
,
Ts
&
...
xs
)
:
mailbox_element
(
std
::
move
(
x0
),
mailbox_category_corrector
<
Ts
...
>::
apply
(
x1
),
std
::
move
(
x2
)),
detail
::
type_erased_tuple_view
<
Ts
...
>
(
xs
...)
{
// nop
}
type_erased_tuple
&
content
()
override
{
return
*
this
;
}
const
type_erased_tuple
&
content
()
const
override
{
return
*
this
;
}
message
move_content_to_message
()
override
{
message_factory
f
;
auto
&
xs
=
this
->
data
();
return
detail
::
apply_moved_args
(
f
,
detail
::
get_indices
(
xs
),
xs
);
}
message
copy_content_to_message
()
const
override
{
message_factory
f
;
auto
&
xs
=
this
->
data
();
return
detail
::
apply_args
(
f
,
detail
::
get_indices
(
xs
),
xs
);
}
};
/// @relates mailbox_element
using
mailbox_element_ptr
=
std
::
unique_ptr
<
mailbox_element
,
detail
::
disposer
>
;
using
mailbox_element_ptr
=
std
::
unique_ptr
<
mailbox_element
>
;
/// @relates mailbox_element
CAF_CORE_EXPORT
mailbox_element_ptr
make_mailbox_element
(
strong_actor_ptr
sender
,
message_id
id
,
mailbox_element
::
forwarding_stack
stages
,
message
msg
);
mailbox_element
::
forwarding_stack
stages
,
message
content
);
/// @relates mailbox_element
template
<
class
T
,
class
...
Ts
>
typename
std
::
enable_if
<
!
std
::
is_same
<
typename
std
::
decay
<
T
>::
type
,
message
>::
value
std
::
enable_if_t
<!
std
::
is_same
<
typename
std
::
decay
<
T
>::
type
,
message
>::
value
||
(
sizeof
...(
Ts
)
>
0
),
mailbox_element_ptr
>::
type
mailbox_element_ptr
>
make_mailbox_element
(
strong_actor_ptr
sender
,
message_id
id
,
mailbox_element
::
forwarding_stack
stages
,
T
&&
x
,
Ts
&&
...
xs
)
{
using
impl
=
mailbox_element_vals
<
typename
unbox_message_element
<
typename
detail
::
strip_and_convert
<
T
>::
type
>::
type
,
typename
unbox_message_element
<
typename
detail
::
strip_and_convert
<
Ts
>::
type
>::
type
...
>
;
auto
ptr
=
new
impl
(
std
::
move
(
sender
),
id
,
std
::
move
(
stages
),
std
::
forward
<
T
>
(
x
),
std
::
forward
<
Ts
>
(
xs
)...);
return
mailbox_element_ptr
{
ptr
};
return
make_mailbox_element
(
std
::
move
(
sender
),
id
,
std
::
move
(
stages
),
make_message
(
std
::
forward
<
T
>
(
x
),
std
::
forward
<
Ts
>
(
xs
)...));
}
}
// namespace caf
libcaf_core/caf/message_view.hpp
deleted
100644 → 0
View file @
ddfd8def
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include "caf/detail/core_export.hpp"
#include "caf/fwd.hpp"
namespace
caf
{
/// Represents an object pointing to a `type_erased_tuple` that
/// is convertible to a `message`
class
CAF_CORE_EXPORT
message_view
{
public:
virtual
~
message_view
();
virtual
type_erased_tuple
&
content
()
=
0
;
virtual
const
type_erased_tuple
&
content
()
const
=
0
;
virtual
message
move_content_to_message
()
=
0
;
virtual
message
copy_content_to_message
()
const
=
0
;
};
}
// namespace caf
libcaf_core/caf/scheduled_actor.hpp
View file @
962d1439
...
...
@@ -84,22 +84,22 @@ namespace caf {
/// @relates scheduled_actor
/// Default handler function that sends the message back to the sender.
CAF_CORE_EXPORT
result
<
message
>
reflect
(
scheduled_actor
*
,
message
_view
&
);
CAF_CORE_EXPORT
result
<
message
>
reflect
(
scheduled_actor
*
,
message
&
);
/// @relates scheduled_actor
/// Default handler function that sends
/// the message back to the sender and then quits.
CAF_CORE_EXPORT
result
<
message
>
reflect_and_quit
(
scheduled_actor
*
,
message
_view
&
);
reflect_and_quit
(
scheduled_actor
*
,
message
&
);
/// @relates scheduled_actor
/// Default handler function that prints messages
/// message via `aout` and drops them afterwards.
CAF_CORE_EXPORT
result
<
message
>
print_and_drop
(
scheduled_actor
*
,
message
_view
&
);
CAF_CORE_EXPORT
result
<
message
>
print_and_drop
(
scheduled_actor
*
,
message
&
);
/// @relates scheduled_actor
/// Default handler function that simply drops messages.
CAF_CORE_EXPORT
result
<
message
>
drop
(
scheduled_actor
*
,
message
_view
&
);
CAF_CORE_EXPORT
result
<
message
>
drop
(
scheduled_actor
*
,
message
&
);
/// A cooperatively scheduled, event-based actor implementation.
/// @extends local_actor
...
...
@@ -192,7 +192,7 @@ public:
/// Function object for handling unmatched messages.
using
default_handler
=
std
::
function
<
result
<
message
>
(
pointer
,
message
_view
&
)
>
;
=
std
::
function
<
result
<
message
>
(
pointer
,
message
&
)
>
;
/// Function object for handling error messages.
using
error_handler
=
std
::
function
<
void
(
pointer
,
error
&
)
>
;
...
...
libcaf_core/caf/skip.hpp
View file @
962d1439
...
...
@@ -31,8 +31,7 @@ namespace caf {
/// skipping to the runtime.
class
CAF_CORE_EXPORT
skip_t
{
public:
using
fun
=
std
::
function
<
result
<
message
>
(
scheduled_actor
*
self
,
message_view
&
)
>
;
using
fun
=
std
::
function
<
result
<
message
>
(
scheduled_actor
*
self
,
message
&
)
>
;
constexpr
skip_t
()
{
// nop
...
...
@@ -45,7 +44,7 @@ public:
operator
fun
()
const
;
private:
static
result
<
message
>
skip_fun_impl
(
scheduled_actor
*
,
message
_view
&
);
static
result
<
message
>
skip_fun_impl
(
scheduled_actor
*
,
message
&
);
};
/// Tells the runtime system to skip a message when used as message
...
...
libcaf_core/src/actor_pool.cpp
View file @
962d1439
...
...
@@ -54,7 +54,7 @@ void broadcast_dispatch(actor_system&, actor_pool::uplock&,
const
actor_pool
::
actor_vec
&
vec
,
mailbox_element_ptr
&
ptr
,
execution_unit
*
host
)
{
CAF_ASSERT
(
!
vec
.
empty
());
auto
msg
=
ptr
->
move_content_to_message
()
;
auto
msg
=
ptr
->
payload
;
for
(
auto
&
worker
:
vec
)
worker
->
enqueue
(
ptr
->
sender
,
ptr
->
mid
,
msg
,
host
);
}
...
...
@@ -117,7 +117,7 @@ actor actor_pool::make(execution_unit* eu, size_t num_workers,
void
actor_pool
::
enqueue
(
mailbox_element_ptr
what
,
execution_unit
*
eu
)
{
upgrade_lock
<
detail
::
shared_spinlock
>
guard
{
workers_mtx_
};
if
(
filter
(
guard
,
what
->
sender
,
what
->
mid
,
*
what
,
eu
))
if
(
filter
(
guard
,
what
->
sender
,
what
->
mid
,
what
->
payload
,
eu
))
return
;
policy_
(
home_system
(),
guard
,
workers_
,
what
,
eu
);
}
...
...
@@ -145,22 +145,20 @@ void actor_pool::on_cleanup(const error& reason) {
bool
actor_pool
::
filter
(
upgrade_lock
<
detail
::
shared_spinlock
>&
guard
,
const
strong_actor_ptr
&
sender
,
message_id
mid
,
message_view
&
mv
,
execution_unit
*
eu
)
{
auto
&
content
=
mv
.
content
();
message
&
content
,
execution_unit
*
eu
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
mid
)
<<
CAF_ARG
(
content
));
if
(
content
.
match_elements
<
exit_msg
>
())
{
// acquire second mutex as well
std
::
vector
<
actor
>
workers
;
auto
em
=
content
.
get_as
<
exit_msg
>
(
0
).
reason
;
if
(
cleanup
(
std
::
move
(
em
),
eu
))
{
auto
tmp
=
mv
.
move_content_to_message
();
// send exit messages *always* to all workers and clear vector afterwards
// but first swap workers_ out of the critical section
upgrade_to_unique_lock
<
detail
::
shared_spinlock
>
unique_guard
{
guard
};
workers_
.
swap
(
workers
);
unique_guard
.
unlock
();
for
(
auto
&
w
:
workers
)
anon_send
(
w
,
tmp
);
anon_send
(
w
,
content
);
unregister_from_system
();
}
return
true
;
...
...
libcaf_core/src/blocking_actor.cpp
View file @
962d1439
...
...
@@ -195,7 +195,7 @@ blocking_actor::mailbox_visitor::operator()(mailbox_element& x) {
return
check_if_done
();
case
match_result
:
:
no_match
:
{
// Blocking actors can have fallback
// handlers for catch-all rules.
auto
sres
=
bhvr
.
fallback
(
*
self
->
current_element_
);
auto
sres
=
bhvr
.
fallback
(
self
->
current_element_
->
payload
);
if
(
sres
.
flag
!=
rt_skip
)
{
visitor
.
visit
(
sres
);
return
check_if_done
();
...
...
@@ -204,10 +204,9 @@ blocking_actor::mailbox_visitor::operator()(mailbox_element& x) {
// Response handlers must get re-invoked with an error when receiving an
// unexpected message.
if
(
mid
.
is_response
())
{
auto
err
=
make_error
(
sec
::
unexpected_response
,
x
.
move_content_to_message
());
mailbox_element_view
<
error
>
tmp
{
std
::
move
(
x
.
sender
),
x
.
mid
,
std
::
move
(
x
.
stages
),
err
};
auto
err
=
make_error
(
sec
::
unexpected_response
,
std
::
move
(
x
.
payload
));
mailbox_element
tmp
{
std
::
move
(
x
.
sender
),
x
.
mid
,
std
::
move
(
x
.
stages
),
make_message
(
std
::
move
(
err
))};
self
->
current_element_
=
&
tmp
;
bhvr
.
nested
(
tmp
.
content
());
return
check_if_done
();
...
...
libcaf_core/src/decorator/splitter.cpp
View file @
962d1439
...
...
@@ -39,8 +39,7 @@ struct splitter_state {
behavior
fan_out_fan_in
(
stateful_actor
<
splitter_state
>*
self
,
const
std
::
vector
<
strong_actor_ptr
>&
workers
)
{
auto
f
=
[
=
](
local_actor
*
,
message_view
&
x
)
->
result
<
message
>
{
auto
msg
=
x
.
move_content_to_message
();
auto
f
=
[
=
](
local_actor
*
,
message
&
msg
)
->
result
<
message
>
{
self
->
state
.
rp
=
self
->
make_response_promise
();
self
->
state
.
pending
=
workers
.
size
();
// request().await() has LIFO ordering
...
...
libcaf_core/src/detail/blocking_behavior.cpp
View file @
962d1439
...
...
@@ -28,7 +28,7 @@ blocking_behavior::blocking_behavior(behavior& x) : nested(x) {
// nop
}
result
<
message
>
blocking_behavior
::
fallback
(
message
_view
&
)
{
result
<
message
>
blocking_behavior
::
fallback
(
message
&
)
{
return
skip
;
}
...
...
libcaf_core/src/forwarding_actor_proxy.cpp
View file @
962d1439
...
...
@@ -58,8 +58,8 @@ void forwarding_actor_proxy::enqueue(mailbox_element_ptr what,
execution_unit
*
)
{
CAF_PUSH_AID
(
0
);
CAF_ASSERT
(
what
);
forward_msg
(
std
::
move
(
what
->
sender
),
what
->
mid
,
what
->
move_content_to_message
(),
&
what
->
stages
);
forward_msg
(
std
::
move
(
what
->
sender
),
what
->
mid
,
std
::
move
(
what
->
payload
),
&
what
->
stages
);
}
bool
forwarding_actor_proxy
::
add_backlink
(
abstract_actor
*
x
)
{
...
...
libcaf_core/src/group_manager.cpp
View file @
962d1439
...
...
@@ -161,8 +161,8 @@ public:
CAF_LOG_TRACE
(
""
);
// instead of dropping "unexpected" messages,
// we simply forward them to our acquaintances
auto
fwd
=
[
=
](
scheduled_actor
*
,
message
_view
&
x
)
->
result
<
message
>
{
send_to_acquaintances
(
x
.
move_content_to_message
(
));
auto
fwd
=
[
=
](
scheduled_actor
*
,
message
&
msg
)
->
result
<
message
>
{
send_to_acquaintances
(
std
::
move
(
msg
));
return
message
{};
};
set_default_handler
(
fwd
);
...
...
@@ -313,9 +313,9 @@ behavior proxy_broker::make_behavior() {
CAF_LOG_TRACE
(
""
);
// instead of dropping "unexpected" messages,
// we simply forward them to our acquaintances
auto
fwd
=
[
=
](
local_actor
*
,
message
_view
&
x
)
->
result
<
message
>
{
group_
->
send_all_subscribers
(
current_element_
->
sender
,
x
.
move_content_to_message
(),
context
());
auto
fwd
=
[
=
](
local_actor
*
,
message
&
msg
)
->
result
<
message
>
{
group_
->
send_all_subscribers
(
current_element_
->
sender
,
std
::
move
(
msg
),
context
());
return
message
{};
};
set_default_handler
(
fwd
);
...
...
libcaf_core/src/mailbox_element.cpp
View file @
962d1439
...
...
@@ -18,80 +18,60 @@
#include "caf/mailbox_element.hpp"
#include
"caf/message_builder.hpp"
#include
<memory>
namespace
caf
{
namespace
{
message_id
dynamic_category_correction
(
const
message
&
msg
,
message_id
mid
)
{
if
(
msg
.
match_elements
<
downstream_msg
>
())
return
mailbox_category_corrector
<
downstream_msg
>::
apply
(
mid
);
if
(
msg
.
match_elements
<
upstream_msg
>
())
return
mailbox_category_corrector
<
upstream_msg
>::
apply
(
mid
);
return
mid
;
}
/// Wraps a `message` into a mailbox element.
class
mailbox_element_wrapper
final
:
public
mailbox_element
{
public:
mailbox_element_wrapper
(
strong_actor_ptr
&&
x0
,
message_id
x1
,
forwarding_stack
&&
x2
,
message
&&
x3
)
:
mailbox_element
(
std
::
move
(
x0
),
dynamic_category_correction
(
x3
,
x1
),
std
::
move
(
x2
)),
msg_
(
std
::
move
(
x3
))
{
/// Make sure that `content` can access the pointer safely.
if
(
msg_
.
vals
()
==
nullptr
)
{
message_builder
mb
;
msg_
=
mb
.
to_message
();
}
}
type_erased_tuple
&
content
()
override
{
return
msg_
;
}
const
type_erased_tuple
&
content
()
const
override
{
return
msg_
.
content
();
/// Corrects the message ID for down- and upstream messages to make sure the
/// category for a `mailbox_element` matches its content.
template
<
class
...
>
struct
mailbox_category_corrector
{
static
constexpr
message_id
apply
(
message_id
x
)
noexcept
{
return
x
;
}
};
message
move_content_to_message
()
override
{
return
std
::
move
(
msg_
);
template
<
>
struct
mailbox_category_corrector
<
downstream_msg
>
{
static
constexpr
message_id
apply
(
message_id
x
)
noexcept
{
return
x
.
with_category
(
message_id
::
downstream_message_category
);
}
};
message
copy_content_to_message
()
const
override
{
return
msg_
;
template
<
>
struct
mailbox_category_corrector
<
upstream_msg
>
{
static
constexpr
message_id
apply
(
message_id
x
)
noexcept
{
return
x
.
with_category
(
message_id
::
upstream_message_category
);
}
private:
/// Stores the content of this mailbox element.
message
msg_
;
};
}
// namespace
mailbox_element
::
mailbox_element
()
{
// nop
message_id
dynamic_category_correction
(
const
message
&
msg
,
message_id
mid
)
{
if
(
msg
.
match_elements
<
downstream_msg
>
())
return
mailbox_category_corrector
<
downstream_msg
>::
apply
(
mid
);
if
(
msg
.
match_elements
<
upstream_msg
>
())
return
mailbox_category_corrector
<
upstream_msg
>::
apply
(
mid
);
return
mid
;
}
mailbox_element
::
mailbox_element
(
strong_actor_ptr
&&
x
,
message_id
y
,
forwarding_stack
&&
z
)
:
sender
(
std
::
move
(
x
)),
mid
(
y
),
stages
(
std
::
move
(
z
))
{
// nop
}
}
// namespace
mailbox_element
::~
mailbox_element
()
{
mailbox_element
::
mailbox_element
(
strong_actor_ptr
sender
,
message_id
mid
,
forwarding_stack
stages
,
message
payload
)
:
sender
(
std
::
move
(
sender
)),
mid
(
dynamic_category_correction
(
payload
,
mid
)),
stages
(
std
::
move
(
stages
)),
payload
(
std
::
move
(
payload
))
{
// nop
}
mailbox_element_ptr
make_mailbox_element
(
strong_actor_ptr
sender
,
message_id
id
,
mailbox_element
::
forwarding_stack
stages
,
message
msg
)
{
auto
ptr
=
new
mailbox_element_wrapper
(
std
::
move
(
sender
),
id
,
std
::
move
(
stages
),
std
::
move
(
msg
));
return
mailbox_element_ptr
{
ptr
}
;
mailbox_element
::
forwarding_stack
stages
,
message
payload
)
{
return
std
::
make_unique
<
mailbox_element
>
(
std
::
move
(
sender
),
id
,
std
::
move
(
stages
),
std
::
move
(
payload
))
;
}
}
// namespace caf
libcaf_core/src/message_view.cpp
deleted
100644 → 0
View file @
ddfd8def
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/message_view.hpp"
namespace
caf
{
message_view
::~
message_view
()
{
// nop
}
}
// namespace caf
libcaf_core/src/raw_event_based_actor.cpp
View file @
962d1439
...
...
@@ -43,7 +43,7 @@ invoke_message_result raw_event_based_actor::consume(mailbox_element& x) {
if
(
!
pr
.
second
(
x
.
content
()))
{
// try again with error if first attempt failed
auto
msg
=
make_message
(
make_error
(
sec
::
unexpected_response
,
x
.
move_content_to_message
(
)));
make_error
(
sec
::
unexpected_response
,
std
::
move
(
x
.
payload
)));
pr
.
second
(
msg
);
}
awaited_responses_
.
pop_front
();
...
...
@@ -58,7 +58,7 @@ invoke_message_result raw_event_based_actor::consume(mailbox_element& x) {
if
(
!
mrh
->
second
(
x
.
content
()))
{
// try again with error if first attempt failed
auto
msg
=
make_message
(
make_error
(
sec
::
unexpected_response
,
x
.
move_content_to_message
(
)));
make_error
(
sec
::
unexpected_response
,
std
::
move
(
x
.
payload
)));
mrh
->
second
(
msg
);
}
multiplexed_responses_
.
erase
(
mrh
);
...
...
@@ -92,7 +92,7 @@ invoke_message_result raw_event_based_actor::consume(mailbox_element& x) {
setf
(
has_timeout_flag
);
});
auto
call_default_handler
=
[
&
]
{
auto
sres
=
call_handler
(
default_handler_
,
this
,
x
);
auto
sres
=
call_handler
(
default_handler_
,
this
,
x
.
payload
);
switch
(
sres
.
flag
)
{
default:
break
;
...
...
libcaf_core/src/scheduled_actor.cpp
View file @
962d1439
...
...
@@ -36,25 +36,25 @@ namespace caf {
// -- related free functions ---------------------------------------------------
result
<
message
>
reflect
(
scheduled_actor
*
,
message
_view
&
x
)
{
return
x
.
move_content_to_message
(
);
result
<
message
>
reflect
(
scheduled_actor
*
,
message
&
msg
)
{
return
std
::
move
(
msg
);
}
result
<
message
>
reflect_and_quit
(
scheduled_actor
*
ptr
,
message
_view
&
x
)
{
result
<
message
>
reflect_and_quit
(
scheduled_actor
*
ptr
,
message
&
msg
)
{
error
err
=
exit_reason
::
normal
;
scheduled_actor
::
default_error_handler
(
ptr
,
err
);
return
reflect
(
ptr
,
x
);
return
reflect
(
ptr
,
msg
);
}
result
<
message
>
print_and_drop
(
scheduled_actor
*
ptr
,
message
_view
&
x
)
{
CAF_LOG_WARNING
(
"unexpected message
"
<<
CAF_ARG
(
x
.
content
())
);
result
<
message
>
print_and_drop
(
scheduled_actor
*
ptr
,
message
&
msg
)
{
CAF_LOG_WARNING
(
"unexpected message
:"
<<
msg
);
aout
(
ptr
)
<<
"*** unexpected message [id: "
<<
ptr
->
id
()
<<
", name: "
<<
ptr
->
name
()
<<
"]: "
<<
x
.
content
().
stringify
(
)
<<
", name: "
<<
ptr
->
name
()
<<
"]: "
<<
to_string
(
msg
)
<<
std
::
endl
;
return
sec
::
unexpected_message
;
}
result
<
message
>
drop
(
scheduled_actor
*
,
message
_view
&
)
{
result
<
message
>
drop
(
scheduled_actor
*
,
message
&
)
{
return
sec
::
unexpected_message
;
}
...
...
@@ -67,7 +67,7 @@ void silently_ignore(scheduled_actor*, T&) {
// nop
}
result
<
message
>
drop_after_quit
(
scheduled_actor
*
self
,
message
_view
&
)
{
result
<
message
>
drop_after_quit
(
scheduled_actor
*
self
,
message
&
)
{
if
(
self
->
current_message_id
().
is_request
())
return
make_error
(
sec
::
request_receiver_down
);
return
make_message
();
...
...
@@ -648,7 +648,7 @@ invoke_message_result scheduled_actor::consume(mailbox_element& x) {
if
(
!
invoke
(
this
,
f
,
x
))
{
// try again with error if first attempt failed
auto
msg
=
make_message
(
make_error
(
sec
::
unexpected_response
,
x
.
move_content_to_message
(
)));
make_error
(
sec
::
unexpected_response
,
std
::
move
(
x
.
payload
)));
f
(
msg
);
}
return
invoke_message_result
::
consumed
;
...
...
@@ -665,7 +665,7 @@ invoke_message_result scheduled_actor::consume(mailbox_element& x) {
if
(
!
invoke
(
this
,
bhvr
,
x
))
{
CAF_LOG_DEBUG
(
"got unexpected_response, invoke as again as error"
);
auto
msg
=
make_message
(
make_error
(
sec
::
unexpected_response
,
x
.
move_content_to_message
(
)));
make_error
(
sec
::
unexpected_response
,
std
::
move
(
x
.
payload
)));
bhvr
(
msg
);
}
return
invoke_message_result
::
consumed
;
...
...
@@ -689,7 +689,7 @@ invoke_message_result scheduled_actor::consume(mailbox_element& x) {
setf
(
has_timeout_flag
);
});
auto
call_default_handler
=
[
&
]
{
auto
sres
=
call_handler
(
default_handler_
,
this
,
x
);
auto
sres
=
call_handler
(
default_handler_
,
this
,
x
.
payload
);
switch
(
sres
.
flag
)
{
default:
break
;
...
...
@@ -1119,7 +1119,7 @@ scheduled_actor::handle_open_stream_msg(mailbox_element& x) {
};
// Utility for invoking the default handler.
auto
fallback
=
[
&
]
{
auto
sres
=
call_handler
(
default_handler_
,
this
,
x
);
auto
sres
=
call_handler
(
default_handler_
,
this
,
x
.
payload
);
switch
(
sres
.
flag
)
{
default:
CAF_LOG_DEBUG
(
...
...
libcaf_core/src/skip.cpp
View file @
962d1439
...
...
@@ -23,7 +23,7 @@
namespace
caf
{
result
<
message
>
skip_t
::
skip_fun_impl
(
scheduled_actor
*
,
message
_view
&
)
{
result
<
message
>
skip_t
::
skip_fun_impl
(
scheduled_actor
*
,
message
&
)
{
return
skip
();
}
...
...
libcaf_core/test/blocking_actor.cpp
View file @
962d1439
...
...
@@ -47,8 +47,8 @@ CAF_TEST(catch_all) {
[](
float
)
{
CAF_FAIL
(
"received unexpected float"
);
},
others
>>
[](
message
_view
&
x
)
->
result
<
message
>
{
CAF_CHECK_EQUAL
(
to_string
(
x
.
content
()
),
"(42)"
);
others
>>
[](
message
&
msg
)
->
result
<
message
>
{
CAF_CHECK_EQUAL
(
to_string
(
msg
),
"(42)"
);
return
sec
::
unexpected_message
;
}
);
...
...
libcaf_core/test/broadcast_downstream_manager.cpp
View file @
962d1439
...
...
@@ -91,7 +91,7 @@ public:
}
void
enqueue
(
mailbox_element_ptr
what
,
execution_unit
*
)
override
{
mbox
.
push_back
(
what
->
move_content_to_message
(
));
mbox
.
push_back
(
std
::
move
(
what
->
payload
));
}
void
attach
(
attachable_ptr
)
override
{
...
...
libcaf_core/test/mailbox_element.cpp
View file @
962d1439
...
...
@@ -73,26 +73,6 @@ CAF_TEST(non_empty_message) {
CAF_CHECK_EQUAL
((
fetch
<
int
,
int
,
int
>
(
*
m1
)),
make_tuple
(
1
,
2
,
3
));
}
CAF_TEST
(
message_roundtrip
)
{
auto
msg
=
make_message
(
1
,
2
,
3
);
auto
msg_ptr
=
msg
.
cvals
().
get
();
auto
m1
=
make_mailbox_element
(
nullptr
,
make_message_id
(),
no_stages
,
std
::
move
(
msg
));
auto
msg2
=
m1
->
move_content_to_message
();
CAF_CHECK_EQUAL
(
msg2
.
cvals
().
get
(),
msg_ptr
);
}
CAF_TEST
(
message_roundtrip_with_copy
)
{
auto
msg
=
make_message
(
1
,
2
,
3
);
auto
msg_ptr
=
msg
.
cvals
().
get
();
auto
m1
=
make_mailbox_element
(
nullptr
,
make_message_id
(),
no_stages
,
std
::
move
(
msg
));
auto
msg2
=
m1
->
copy_content_to_message
();
auto
msg3
=
m1
->
move_content_to_message
();
CAF_CHECK_EQUAL
(
msg2
.
cvals
().
get
(),
msg_ptr
);
CAF_CHECK_EQUAL
(
msg3
.
cvals
().
get
(),
msg_ptr
);
}
CAF_TEST
(
tuple
)
{
auto
m1
=
make_mailbox_element
(
nullptr
,
make_message_id
(),
no_stages
,
1
,
2
,
3
);
...
...
@@ -103,26 +83,6 @@ CAF_TEST(tuple) {
CAF_CHECK_EQUAL
((
fetch
<
int
,
int
,
int
>
(
*
m1
)),
make_tuple
(
1
,
2
,
3
));
}
CAF_TEST
(
move_tuple
)
{
auto
m1
=
make_mailbox_element
(
nullptr
,
make_message_id
(),
no_stages
,
"hello"
,
"world"
);
using
strings
=
tuple
<
string
,
string
>
;
CAF_CHECK_EQUAL
((
fetch
<
string
,
string
>
(
*
m1
)),
strings
(
"hello"
,
"world"
));
auto
msg
=
m1
->
move_content_to_message
();
CAF_CHECK_EQUAL
((
fetch
<
string
,
string
>
(
msg
)),
strings
(
"hello"
,
"world"
));
CAF_CHECK_EQUAL
((
fetch
<
string
,
string
>
(
*
m1
)),
strings
(
""
,
""
));
}
CAF_TEST
(
copy_tuple
)
{
auto
m1
=
make_mailbox_element
(
nullptr
,
make_message_id
(),
no_stages
,
"hello"
,
"world"
);
using
strings
=
tuple
<
string
,
string
>
;
CAF_CHECK_EQUAL
((
fetch
<
string
,
string
>
(
*
m1
)),
strings
(
"hello"
,
"world"
));
auto
msg
=
m1
->
copy_content_to_message
();
CAF_CHECK_EQUAL
((
fetch
<
string
,
string
>
(
msg
)),
strings
(
"hello"
,
"world"
));
CAF_CHECK_EQUAL
((
fetch
<
string
,
string
>
(
*
m1
)),
strings
(
"hello"
,
"world"
));
}
CAF_TEST
(
high_priority
)
{
auto
m1
=
make_mailbox_element
(
nullptr
,
make_message_id
(
message_priority
::
high
),
...
...
libcaf_io/caf/io/broker_servant.hpp
View file @
962d1439
...
...
@@ -36,7 +36,8 @@ public:
broker_servant
(
handle_type
x
)
:
hdl_
(
x
),
value_
(
strong_actor_ptr
{},
make_message_id
(),
mailbox_element
::
forwarding_stack
{},
SysMsgType
{
x
,
{}})
{
mailbox_element
::
forwarding_stack
{},
make_message
(
SysMsgType
{
x
,
{}}))
{
// nop
}
...
...
@@ -103,9 +104,9 @@ protected:
std
::
is_same
<
handle_type
,
accept_handle
>::
value
,
acceptor_passivated_msg
,
datagram_servant_passivated_msg
>::
type
>::
type
;
using
tmp_t
=
mailbox_element_vals
<
passiv_t
>
;
tmp_t
tmp
{
strong_actor_ptr
{},
make_message_id
()
,
mailbox_element
::
forwarding_stack
{},
passiv_t
{
hdl
()}
};
mailbox_element
tmp
{
strong_actor_ptr
{},
make_message_id
(),
mailbox_element
::
forwarding_stack
{}
,
make_message
(
passiv_t
{
hdl
()})
};
invoke_mailbox_element_impl
(
ctx
,
tmp
);
return
activity_tokens_
!=
size_t
{
0
};
}
...
...
@@ -113,11 +114,11 @@ protected:
}
SysMsgType
&
msg
()
{
return
value_
.
template
get_mutable_as
<
SysMsgType
>(
0
);
return
value_
.
payload
.
template
get_mutable_as
<
SysMsgType
>(
0
);
}
handle_type
hdl_
;
mailbox_element
_vals
<
SysMsgType
>
value_
;
mailbox_element
value_
;
optional
<
size_t
>
activity_tokens_
;
};
...
...
libcaf_io/src/io/datagram_servant.cpp
View file @
962d1439
...
...
@@ -65,10 +65,9 @@ void datagram_servant::datagram_sent(execution_unit* ctx, datagram_handle hdl,
if
(
detached
())
return
;
using
sent_t
=
datagram_sent_msg
;
using
tmp_t
=
mailbox_element_vals
<
datagram_sent_msg
>
;
tmp_t
tmp
{
strong_actor_ptr
{},
make_message_id
(),
mailbox_element
tmp
{
strong_actor_ptr
{},
make_message_id
(),
mailbox_element
::
forwarding_stack
{},
sent_t
{
hdl
,
written
,
std
::
move
(
buffer
)}
};
make_message
(
sent_t
{
hdl
,
written
,
std
::
move
(
buffer
)})
};
invoke_mailbox_element_impl
(
ctx
,
tmp
);
}
...
...
libcaf_io/src/io/scribe.cpp
View file @
962d1439
...
...
@@ -65,10 +65,9 @@ void scribe::data_transferred(execution_unit* ctx, size_t written,
if
(
detached
())
return
;
using
transferred_t
=
data_transferred_msg
;
using
tmp_t
=
mailbox_element_vals
<
data_transferred_msg
>
;
tmp_t
tmp
{
strong_actor_ptr
{},
make_message_id
(),
mailbox_element
tmp
{
strong_actor_ptr
{},
make_message_id
(),
mailbox_element
::
forwarding_stack
{},
transferred_t
{
hdl
(),
written
,
remaining
}
};
make_message
(
transferred_t
{
hdl
(),
written
,
remaining
})
};
invoke_mailbox_element_impl
(
ctx
,
tmp
);
// data_transferred_msg tmp{hdl(), written, remaining};
// auto ptr = make_mailbox_element(nullptr, invalid_message_id, {}, tmp);
...
...
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