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
de67a79d
Commit
de67a79d
authored
Sep 30, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement delayed_send for groups
parent
9ae52879
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
12 deletions
+90
-12
libcaf_core/caf/mixin/sender.hpp
libcaf_core/caf/mixin/sender.hpp
+25
-12
libcaf_core/test/delayed_send.cpp
libcaf_core/test/delayed_send.cpp
+65
-0
No files found.
libcaf_core/caf/mixin/sender.hpp
View file @
de67a79d
...
@@ -99,7 +99,7 @@ public:
...
@@ -99,7 +99,7 @@ public:
}
}
template
<
message_priority
P
=
message_priority
::
normal
,
template
<
message_priority
P
=
message_priority
::
normal
,
class
Source
=
actor
,
class
Dest
=
actor
,
class
...
Ts
>
class
Dest
=
actor
,
class
...
Ts
>
void
anon_send
(
const
Dest
&
dest
,
Ts
&&
...
xs
)
{
void
anon_send
(
const
Dest
&
dest
,
Ts
&&
...
xs
)
{
static_assert
(
sizeof
...(
Ts
)
>
0
,
"no message to send"
);
static_assert
(
sizeof
...(
Ts
)
>
0
,
"no message to send"
);
using
token
=
using
token
=
...
@@ -157,16 +157,13 @@ public:
...
@@ -157,16 +157,13 @@ public:
if
(
dest
)
{
if
(
dest
)
{
auto
&
clock
=
dptr
()
->
system
().
clock
();
auto
&
clock
=
dptr
()
->
system
().
clock
();
auto
t
=
clock
.
now
()
+
rtime
;
auto
t
=
clock
.
now
()
+
rtime
;
auto
me
=
make_mailbox_element
(
dptr
()
->
ctrl
(),
make_message_id
(
P
),
delayed_send_impl
(
clock
,
dptr
()
->
ctrl
(),
dest
,
P
,
t
,
no_stages
,
std
::
forward
<
Ts
>
(
xs
)...);
std
::
forward
<
Ts
>
(
xs
)...);
clock
.
schedule_message
(
t
,
actor_cast
<
strong_actor_ptr
>
(
dest
),
std
::
move
(
me
));
}
}
}
}
template
<
message_priority
P
=
message_priority
::
normal
,
class
Rep
=
int
,
template
<
message_priority
P
=
message_priority
::
normal
,
class
Dest
=
actor
,
class
Period
=
std
::
ratio
<
1
>,
class
Source
=
actor
,
class
Rep
=
int
,
class
Period
=
std
::
ratio
<
1
>,
class
...
Ts
>
class
Dest
=
actor
,
class
...
Ts
>
void
delayed_anon_send
(
const
Dest
&
dest
,
void
delayed_anon_send
(
const
Dest
&
dest
,
std
::
chrono
::
duration
<
Rep
,
Period
>
rtime
,
Ts
&&
...
xs
)
{
std
::
chrono
::
duration
<
Rep
,
Period
>
rtime
,
Ts
&&
...
xs
)
{
static_assert
(
sizeof
...(
Ts
)
>
0
,
"no message to send"
);
static_assert
(
sizeof
...(
Ts
)
>
0
,
"no message to send"
);
...
@@ -183,10 +180,7 @@ public:
...
@@ -183,10 +180,7 @@ public:
if
(
dest
)
{
if
(
dest
)
{
auto
&
clock
=
dptr
()
->
system
().
clock
();
auto
&
clock
=
dptr
()
->
system
().
clock
();
auto
t
=
clock
.
now
()
+
rtime
;
auto
t
=
clock
.
now
()
+
rtime
;
auto
me
=
make_mailbox_element
(
nullptr
,
make_message_id
(
P
),
no_stages
,
delayed_send_impl
(
clock
,
nullptr
,
dest
,
P
,
t
,
std
::
forward
<
Ts
>
(
xs
)...);
std
::
forward
<
Ts
>
(
xs
)...);
clock
.
schedule_message
(
t
,
actor_cast
<
strong_actor_ptr
>
(
dest
),
std
::
move
(
me
));
}
}
}
}
...
@@ -194,6 +188,25 @@ private:
...
@@ -194,6 +188,25 @@ private:
Subtype
*
dptr
()
{
Subtype
*
dptr
()
{
return
static_cast
<
Subtype
*>
(
this
);
return
static_cast
<
Subtype
*>
(
this
);
}
}
template
<
class
...
Ts
>
static
void
delayed_send_impl
(
actor_clock
&
clk
,
strong_actor_ptr
src
,
const
group
&
dst
,
message_priority
,
actor_clock
::
time_point
tout
,
Ts
&&
...
xs
)
{
clk
.
schedule_message
(
tout
,
dst
,
std
::
move
(
src
),
make_message
(
std
::
forward
<
Ts
>
(
xs
)...));
}
template
<
class
ActorHandle
,
class
...
Ts
>
static
void
delayed_send_impl
(
actor_clock
&
clk
,
strong_actor_ptr
src
,
const
ActorHandle
&
dst
,
message_priority
prio
,
actor_clock
::
time_point
tout
,
Ts
&&
...
xs
)
{
clk
.
schedule_message
(
tout
,
actor_cast
<
strong_actor_ptr
>
(
dst
),
make_mailbox_element
(
std
::
move
(
src
),
make_message_id
(
prio
),
no_stages
,
std
::
forward
<
Ts
>
(
xs
)...));
}
};
};
}
// namespace mixin
}
// namespace mixin
...
...
libcaf_core/test/delayed_send.cpp
0 → 100644
View file @
de67a79d
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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. *
******************************************************************************/
#define CAF_SUITE delayed_send
#include <chrono>
#include "caf/actor_system.hpp"
#include "caf/behavior.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/test/dsl.hpp"
using
namespace
caf
;
using
std
::
chrono
::
seconds
;
namespace
{
behavior
testee_impl
(
event_based_actor
*
self
)
{
self
->
set_default_handler
(
drop
);
return
{
[]
{
// nop
}
};
}
}
// namespace <anonymous>
CAF_TEST_FIXTURE_SCOPE
(
request_timeout_tests
,
test_coordinator_fixture
<>
)
CAF_TEST
(
delayed
actor
message
)
{
auto
testee
=
sys
.
spawn
(
testee_impl
);
self
->
delayed_send
(
testee
,
seconds
(
1
),
"hello world"
);
sched
.
trigger_timeout
();
expect
((
std
::
string
),
from
(
self
).
to
(
testee
).
with
(
"hello world"
));
}
CAF_TEST
(
delayed
group
message
)
{
auto
grp
=
sys
.
groups
().
anonymous
();
auto
testee
=
sys
.
spawn_in_group
(
grp
,
testee_impl
);
self
->
delayed_send
(
grp
,
seconds
(
1
),
"hello world"
);
sched
.
trigger_timeout
();
expect
((
std
::
string
),
from
(
self
).
to
(
testee
).
with
(
"hello world"
));
// The group keeps a reference, so we need to shutdown 'manually'.
anon_send_exit
(
testee
,
exit_reason
::
user_shutdown
);
}
CAF_TEST_FIXTURE_SCOPE_END
()
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