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
8d1b0361
Commit
8d1b0361
authored
Jan 23, 2014
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replaced 'EXIT' and 'DOWN' messages w/ msg types
parent
d2afafff
Changes
22
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
277 additions
and
520 deletions
+277
-520
cppa.files
cppa.files
+1
-2
cppa/behavior_stack_based.hpp
cppa/behavior_stack_based.hpp
+2
-1
cppa/cppa.hpp
cppa/cppa.hpp
+1
-0
cppa/detail/proper_actor.hpp
cppa/detail/proper_actor.hpp
+1
-1
cppa/detail/response_future_util.hpp
cppa/detail/response_future_util.hpp
+2
-1
cppa/detail/uniform_type_info_map.hpp
cppa/detail/uniform_type_info_map.hpp
+5
-0
cppa/policy/invoke_policy.hpp
cppa/policy/invoke_policy.hpp
+20
-21
cppa/send.hpp
cppa/send.hpp
+0
-347
cppa/system_messages.hpp
cppa/system_messages.hpp
+54
-41
examples/remote_actors/distributed_calculator.cpp
examples/remote_actors/distributed_calculator.cpp
+1
-1
examples/remote_actors/protobuf_broker.cpp
examples/remote_actors/protobuf_broker.cpp
+2
-2
manual.pdf
manual.pdf
+0
-0
src/abstract_actor.cpp
src/abstract_actor.cpp
+7
-3
src/group_manager.cpp
src/group_manager.cpp
+3
-3
src/local_actor.cpp
src/local_actor.cpp
+3
-3
src/scheduler.cpp
src/scheduler.cpp
+2
-1
src/uniform_type_info_map.cpp
src/uniform_type_info_map.cpp
+109
-57
unit_testing/test_broker.cpp
unit_testing/test_broker.cpp
+4
-4
unit_testing/test_remote_actor.cpp
unit_testing/test_remote_actor.cpp
+10
-10
unit_testing/test_spawn.cpp
unit_testing/test_spawn.cpp
+29
-14
unit_testing/test_sync_send.cpp
unit_testing/test_sync_send.cpp
+16
-7
unit_testing/test_uniform_type.cpp
unit_testing/test_uniform_type.cpp
+5
-1
No files found.
cppa.files
View file @
8d1b0361
...
...
@@ -140,7 +140,6 @@ cppa/response_promise.hpp
cppa/sb_actor.hpp
cppa/scheduler.hpp
cppa/scoped_actor.hpp
cppa/send.hpp
cppa/serializer.hpp
cppa/singletons.hpp
cppa/spawn.hpp
...
...
@@ -279,7 +278,6 @@ src/response_promise.cpp
src/ripemd_160.cpp
src/scheduler.cpp
src/scoped_actor.cpp
src/send.cpp
src/serializer.cpp
src/shared_spinlock.cpp
src/singleton_manager.cpp
...
...
@@ -339,3 +337,4 @@ src/functor_based_blocking_actor.cpp
src/blocking_untyped_actor.cpp
cppa/policy/policies.hpp
cppa/detail/response_future_util.hpp
cppa/system_messages.hpp
cppa/behavior_stack_based.hpp
View file @
8d1b0361
...
...
@@ -32,6 +32,7 @@
#define CPPA_BEHAVIOR_STACK_BASED_HPP
#include "cppa/message_id.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/detail/behavior_stack.hpp"
...
...
@@ -163,7 +164,7 @@ class behavior_stack_based : public Base {
if
(
d
.
valid
())
{
m_has_timeout
=
true
;
auto
tid
=
++
m_timeout_id
;
auto
msg
=
make_any_tuple
(
atom
(
"SYNC_TOUT"
),
tid
);
auto
msg
=
make_any_tuple
(
timeout_msg
{
tid
}
);
if
(
d
.
is_zero
())
{
// immediately enqueue timeout message if duration == 0s
this
->
enqueue
({
this
->
address
(),
this
},
std
::
move
(
msg
));
...
...
cppa/cppa.hpp
View file @
8d1b0361
...
...
@@ -59,6 +59,7 @@
#include "cppa/spawn_options.hpp"
#include "cppa/untyped_actor.hpp"
#include "cppa/abstract_actor.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/response_promise.hpp"
#include "cppa/blocking_untyped_actor.hpp"
...
...
cppa/detail/proper_actor.hpp
View file @
8d1b0361
...
...
@@ -298,7 +298,7 @@ class proper_actor<Base, Policies,true> : public proper_actor_base<Base,
std
::
uint32_t
request_timeout
(
const
util
::
duration
&
d
)
{
CPPA_REQUIRE
(
d
.
valid
());
auto
tid
=
++
m_next_timeout_id
;
auto
msg
=
make_any_tuple
(
atom
(
"SYNC_TOUT"
),
tid
);
auto
msg
=
make_any_tuple
(
timeout_msg
{
tid
}
);
if
(
d
.
is_zero
())
{
// immediately enqueue timeout message if duration == 0s
this
->
enqueue
({
this
->
address
(),
this
},
std
::
move
(
msg
));
...
...
cppa/detail/response_future_util.hpp
View file @
8d1b0361
...
...
@@ -33,6 +33,7 @@
#include "cppa/on.hpp"
#include "cppa/match_hint.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/util/type_traits.hpp"
...
...
@@ -46,7 +47,7 @@ behavior fs2bhvr(Actor* self, Fs... fs) {
return
match_hint
::
skip
;
};
return
behavior
{
on
(
atom
(
"TIMEOUT"
)
)
>>
handle_sync_timeout
,
on
<
sync_timeout_msg
>
(
)
>>
handle_sync_timeout
,
on
(
atom
(
"VOID"
))
>>
skip_message
,
on
(
atom
(
"EXITED"
))
>>
skip_message
,
(
on
(
any_vals
,
arg_match
)
>>
std
::
move
(
fs
))...
...
...
cppa/detail/uniform_type_info_map.hpp
View file @
8d1b0361
...
...
@@ -43,6 +43,7 @@
#include "cppa/unit.hpp"
#include "cppa/none.hpp"
#include "cppa/node_id.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/util/buffer.hpp"
#include "cppa/util/duration.hpp"
...
...
@@ -65,11 +66,15 @@ using mapped_type_list = util::type_list<
any_tuple
,
atom_value
,
channel
,
down_msg
,
exit_msg
,
group_ptr
,
node_id_ptr
,
io
::
accept_handle
,
io
::
connection_handle
,
message_header
,
sync_timeout_msg
,
timeout_msg
,
unit_t
,
util
::
buffer
,
util
::
duration
,
...
...
cppa/policy/invoke_policy.hpp
View file @
8d1b0361
...
...
@@ -43,6 +43,7 @@
#include "cppa/message_id.hpp"
#include "cppa/exit_reason.hpp"
#include "cppa/mailbox_element.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/partial_function.hpp"
#include "cppa/response_promise.hpp"
...
...
@@ -152,35 +153,33 @@ class invoke_policy {
filter_result
filter_msg
(
Actor
*
self
,
mailbox_element
*
node
)
{
const
any_tuple
&
msg
=
node
->
msg
;
auto
mid
=
node
->
mid
;
auto
&
arr
=
detail
::
static_types_array
<
atom_value
,
std
::
uint32_t
>::
arr
;
if
(
msg
.
size
()
==
2
&&
msg
.
type_at
(
0
)
==
arr
[
0
]
&&
msg
.
type_at
(
1
)
==
arr
[
1
])
{
auto
v0
=
msg
.
get_as
<
atom_value
>
(
0
);
auto
v1
=
msg
.
get_as
<
std
::
uint32_t
>
(
1
);
if
(
v0
==
atom
(
"EXIT"
))
{
auto
&
arr
=
detail
::
static_types_array
<
exit_msg
,
timeout_msg
,
sync_timeout_msg
>::
arr
;
if
(
msg
.
size
()
==
1
)
{
if
(
msg
.
type_at
(
0
)
==
arr
[
0
])
{
auto
&
em
=
msg
.
get_as
<
exit_msg
>
(
0
);
CPPA_REQUIRE
(
!
mid
.
valid
());
if
(
self
->
trap_exit
()
==
false
)
{
if
(
v1
!=
exit_reason
::
normal
)
{
self
->
quit
(
v1
);
if
(
em
.
reason
!=
exit_reason
::
normal
)
{
self
->
quit
(
em
.
reason
);
return
non_normal_exit_signal
;
}
return
normal_exit_signal
;
}
}
else
if
(
v0
==
atom
(
"SYNC_TOUT"
))
{
else
if
(
msg
.
type_at
(
0
)
==
arr
[
1
])
{
auto
&
tm
=
msg
.
get_as
<
timeout_msg
>
(
0
);
auto
tid
=
tm
.
timeout_id
;
CPPA_REQUIRE
(
!
mid
.
valid
());
if
(
self
->
is_active_timeout
(
v1
))
return
timeout_message
;
return
self
->
waits_for_timeout
(
v1
)
?
inactive_timeout_message
if
(
self
->
is_active_timeout
(
tid
))
return
timeout_message
;
return
self
->
waits_for_timeout
(
tid
)
?
inactive_timeout_message
:
expired_timeout_message
;
}
}
else
if
(
msg
.
size
()
==
1
&&
msg
.
type_at
(
0
)
==
arr
[
0
]
&&
msg
.
get_as
<
atom_value
>
(
0
)
==
atom
(
"TIMEOUT"
)
&&
mid
.
is_response
())
{
else
if
(
msg
.
type_at
(
0
)
==
arr
[
2
]
&&
mid
.
is_response
())
{
return
timeout_response_message
;
}
}
if
(
mid
.
is_response
())
{
return
(
self
->
awaits
(
mid
))
?
sync_response
:
expired_sync_response
;
...
...
@@ -322,8 +321,8 @@ class invoke_policy {
}
case
timeout_message
:
{
CPPA_LOG_DEBUG
(
"handle timeout message"
);
auto
tid
=
node
->
msg
.
get_as
<
std
::
uint32_t
>
(
1
);
self
->
handle_timeout
(
fun
,
tid
);
auto
&
tm
=
node
->
msg
.
get_as
<
timeout_msg
>
(
0
);
self
->
handle_timeout
(
fun
,
t
m
.
timeout_
id
);
if
(
awaited_response
.
valid
())
{
self
->
mark_arrived
(
awaited_response
);
self
->
remove_handler
(
awaited_response
);
...
...
cppa/send.hpp
deleted
100644 → 0
View file @
d2afafff
This diff is collapsed.
Click to expand it.
src/send.c
pp
→
cppa/system_messages.h
pp
View file @
8d1b0361
...
...
@@ -28,52 +28,65 @@
\******************************************************************************/
#i
nclude "cppa/scheduler.hpp"
#
include "cppa/singletons.hpp"
#i
fndef CPPA_SYSTEM_MESSAGES_HPP
#
define CPPA_SYSTEM_MESSAGES_HPP
namespace
cppa
{
#include <cstdint>
#include "cppa/actor_addr.hpp"
response_future
sync_send_tuple
(
actor_destination
dest
,
any_tuple
what
)
{
if
(
!
dest
.
receiver
)
throw
std
::
invalid_argument
(
"whom == nullptr"
);
auto
req
=
self
->
new_request_id
();
message_header
hdr
{
self
,
std
::
move
(
dest
.
receiver
),
req
,
dest
.
priority
};
if
(
self
->
chaining_enabled
())
{
if
(
hdr
.
receiver
->
chained_enqueue
(
hdr
,
std
::
move
(
what
)))
{
self
->
chained_actor
(
hdr
.
receiver
.
downcast
<
actor
>
());
}
}
else
hdr
.
deliver
(
std
::
move
(
what
));
return
req
.
response_id
();
}
namespace
cppa
{
void
delayed_send_tuple
(
channel_destination
dest
,
const
util
::
duration
&
rtime
,
any_tuple
data
)
{
if
(
dest
.
receiver
)
{
message_header
hdr
{
self
,
std
::
move
(
dest
.
receiver
),
dest
.
priority
};
get_scheduler
()
->
delayed_send
(
std
::
move
(
hdr
),
rtime
,
std
::
move
(
data
));
}
}
/**
* @brief Sent to all links when an actor is terminated.
* @note This message can be handled manually by calling
* {@link local_actor::trap_exit(true) local_actor::trap_exit(bool)}
* and is otherwise handled implicitly by the runtime system.
*/
struct
exit_msg
{
/**
* @brief The source of this message, i.e., the terminated actor.
*/
actor_addr
source
;
/**
* @brief The exit reason of the terminated actor.
*/
std
::
uint32_t
reason
;
};
response_future
timed_sync_send_tuple
(
actor_destination
dest
,
const
util
::
duration
&
rtime
,
any_tuple
what
)
{
auto
mf
=
sync_send_tuple
(
std
::
move
(
dest
),
std
::
move
(
what
));
message_header
hdr
{
self
,
self
,
mf
.
id
()};
auto
tmp
=
make_any_tuple
(
atom
(
"TIMEOUT"
));
get_scheduler
()
->
delayed_send
(
std
::
move
(
hdr
),
rtime
,
std
::
move
(
tmp
));
return
mf
;
}
/**
* @brief Sent to all actors monitoring an actor when it is terminated.
*/
struct
down_msg
{
/**
* @brief The source of this message, i.e., the terminated actor.
*/
actor_addr
source
;
/**
* @brief The exit reason of the terminated actor.
*/
std
::
uint32_t
reason
;
};
void
delayed_reply_tuple
(
const
util
::
duration
&
rtime
,
message_id
mid
,
any_tuple
data
)
{
message_header
hdr
{
self
,
self
->
last_sender
(),
mid
};
get_scheduler
()
->
delayed_send
(
std
::
move
(
hdr
),
rtime
,
std
::
move
(
data
));
}
/**
* @brief Sent whenever a timeout occurs during a synchronous send.
*
* This system message does not have any fields, because the message ID
* sent alongside this message identifies the matching request that timed out.
*/
struct
sync_timeout_msg
{
};
void
delayed_reply_tuple
(
const
util
::
duration
&
rel_time
,
any_tuple
data
)
{
delayed_reply_tuple
(
rel_time
,
self
->
get_response_id
(),
std
::
move
(
data
));
}
/**
* @brief Signalizes a timeout event.
* @note This message is handled implicitly by the runtime system.
*/
struct
timeout_msg
{
/**
* @brief Actor-specific timeout ID.
*/
std
::
uint32_t
timeout_id
;
};
}
// namespace cppa
#endif // CPPA_SYSTEM_MESSAGES_HPP
examples/remote_actors/distributed_calculator.cpp
View file @
8d1b0361
...
...
@@ -83,7 +83,7 @@ void client_bhvr(untyped_actor* self, const string& host, uint16_t port, const a
}
);
},
on
(
atom
(
"DOWN"
),
arg_match
)
>>
[
=
](
uint32_t
)
{
on
_arg_match
>>
[
=
](
const
down_msg
&
)
{
aout
<<
"*** server down, try to reconnect ..."
<<
endl
;
client_bhvr
(
self
,
host
,
port
,
nullptr
);
},
...
...
examples/remote_actors/protobuf_broker.cpp
View file @
8d1b0361
...
...
@@ -104,8 +104,8 @@ void protobuf_io(broker* thisptr, connection_handle hdl, const actor_ptr& buddy)
p
.
mutable_pong
()
->
set_id
(
i
);
write
(
p
);
},
on
(
atom
(
"DOWN"
),
arg_match
)
>>
[
=
](
uint32_t
rsn
)
{
if
(
self
->
last_sender
()
==
buddy
)
self
->
quit
(
rs
n
);
on
_arg_match
>>
[
=
](
const
down_msg
&
dm
)
{
if
(
dm
.
source
==
buddy
)
self
->
quit
(
dm
.
reaso
n
);
},
others
()
>>
[
=
]
{
cout
<<
"unexpected: "
<<
to_string
(
self
->
last_dequeued
())
<<
endl
;
...
...
manual.pdf
View file @
8d1b0361
No preview for this file type
src/abstract_actor.cpp
View file @
8d1b0361
...
...
@@ -43,6 +43,7 @@
#include "cppa/actor_addr.hpp"
#include "cppa/abstract_actor.hpp"
#include "cppa/message_header.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/util/shared_spinlock.hpp"
#include "cppa/util/shared_lock_guard.hpp"
...
...
@@ -71,7 +72,8 @@ bool abstract_actor::link_to_impl(const actor_addr& other) {
auto
ptr
=
detail
::
actor_addr_cast
<
abstract_actor
>
(
other
);
// send exit message if already exited
if
(
exited
())
{
ptr
->
enqueue
({
address
(),
ptr
},
make_any_tuple
(
atom
(
"EXIT"
),
exit_reason
()));
ptr
->
enqueue
({
address
(),
ptr
},
make_any_tuple
(
exit_msg
{
address
(),
exit_reason
()}));
}
// add link if not already linked to other
// (checked by establish_backlink)
...
...
@@ -152,7 +154,9 @@ bool abstract_actor::establish_backlink(const actor_addr& other) {
}
// send exit message without lock
if
(
reason
!=
exit_reason
::
not_exited
)
{
//send_as(this, other, make_any_tuple(atom("EXIT"), reason));
auto
ptr
=
detail
::
raw_access
::
unsafe_cast
(
other
);
ptr
.
enqueue
({
address
(),
ptr
},
make_any_tuple
(
exit_msg
{
address
(),
exit_reason
()}));
}
return
false
;
}
...
...
@@ -202,7 +206,7 @@ void abstract_actor::cleanup(std::uint32_t reason) {
<<
" attached functors; exit reason = "
<<
reason
<<
", class = "
<<
detail
::
demangle
(
typeid
(
*
this
)));
// send exit messages
auto
msg
=
make_any_tuple
(
atom
(
"EXIT"
),
reason
);
auto
msg
=
make_any_tuple
(
exit_msg
{
address
(),
reason
}
);
CPPA_LOGM_DEBUG
(
"cppa::actor"
,
"send EXIT to "
<<
mlinks
.
size
()
<<
" links"
);
for
(
auto
&
aptr
:
mlinks
)
{
aptr
->
enqueue
({
address
(),
aptr
,
message_id
{}.
with_high_priority
()},
msg
);
...
...
src/group_manager.cpp
View file @
8d1b0361
...
...
@@ -163,7 +163,7 @@ class local_broker : public untyped_actor {
// forward to all acquaintances
send_to_acquaintances
(
what
);
},
on
(
atom
(
"DOWN"
),
arg_match
)
>>
[
=
](
uint32_t
)
{
on
_arg_match
>>
[
=
](
const
down_msg
&
)
{
auto
sender
=
last_sender
();
CPPA_LOGC_TRACE
(
"cppa::local_broker"
,
"init$DOWN"
,
CPPA_TARG
(
sender
,
to_string
));
...
...
@@ -519,13 +519,13 @@ class remote_group_module : public group::module {
sm
->
put
(
key
,
nullptr
);
}
},
on
(
atom
(
"TIMEOUT"
)
)
>>
[
sm
,
&
key
]
{
on
<
sync_timeout_msg
>
(
)
>>
[
sm
,
&
key
]
{
sm
->
put
(
key
,
nullptr
);
}
);
}
},
on
<
atom
(
"DOWN"
),
std
::
uint32_t
>
()
>>
[
&
]
{
on
_arg_match
>>
[
&
](
const
down_msg
&
)
{
auto
who
=
self
->
last_sender
();
auto
find_peer
=
[
&
]
{
return
find_if
(
begin
(
*
peers
),
end
(
*
peers
),
[
&
](
const
peer_map
::
value_type
&
kvp
)
{
...
...
src/local_actor.cpp
View file @
8d1b0361
...
...
@@ -58,7 +58,7 @@ class down_observer : public attachable {
if
(
m_observer
)
{
auto
ptr
=
detail
::
actor_addr_cast
<
abstract_actor
>
(
m_observer
);
message_header
hdr
{
m_observed
,
ptr
,
message_id
{}.
with_high_priority
()};
hdr
.
deliver
(
make_any_tuple
(
atom
(
"DOWN"
),
reason
));
hdr
.
deliver
(
make_any_tuple
(
down_msg
{
m_observed
,
reason
}
));
}
}
...
...
@@ -154,7 +154,7 @@ void local_actor::send_tuple(const channel& dest, any_tuple what) {
}
void
local_actor
::
send_exit
(
const
actor_addr
&
whom
,
std
::
uint32_t
reason
)
{
send
(
detail
::
raw_access
::
get
(
whom
),
atom
(
"EXIT"
),
reason
);
send
(
detail
::
raw_access
::
get
(
whom
),
exit_msg
{
address
(),
reason
}
);
}
void
local_actor
::
delayed_send_tuple
(
const
channel
&
dest
,
...
...
@@ -203,7 +203,7 @@ message_id local_actor::timed_sync_send_tuple_impl(message_priority mp,
dest
.
enqueue
({
address
(),
dest
,
nri
},
std
::
move
(
what
));
auto
rri
=
nri
.
response_id
();
get_scheduler
()
->
delayed_send
({
address
(),
this
,
rri
},
rtime
,
make_any_tuple
(
atom
(
"TIMEOUT"
)
));
make_any_tuple
(
sync_timeout_msg
{}
));
return
rri
;
}
...
...
src/scheduler.cpp
View file @
8d1b0361
...
...
@@ -41,6 +41,7 @@
#include "cppa/scheduler.hpp"
#include "cppa/local_actor.hpp"
#include "cppa/scoped_actor.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/detail/proper_actor.hpp"
#include "cppa/detail/actor_registry.hpp"
...
...
@@ -241,7 +242,7 @@ void scheduler_helper::printer_loop(blocking_untyped_actor* self) {
on
(
atom
(
"flush"
))
>>
[
&
]
{
flush_output
(
self
->
last_sender
());
},
on
(
atom
(
"DOWN"
),
any_vals
)
>>
[
&
]
{
on
_arg_match
>>
[
&
](
const
down_msg
&
)
{
auto
s
=
self
->
last_sender
();
flush_output
(
s
);
out
.
erase
(
s
);
...
...
src/uniform_type_info_map.cpp
View file @
8d1b0361
...
...
@@ -65,11 +65,15 @@ namespace cppa { namespace detail {
{
"cppa::any_tuple"
,
"@tuple"
},
{
"cppa::atom_value"
,
"@atom"
},
{
"cppa::channel"
,
"@channel"
},
{
"cppa::down_msg"
,
"@down"
},
{
"cppa::exit_msg"
,
"@exit"
},
{
"cppa::intrusive_ptr<cppa::group>"
,
"@group"
},
{
"cppa::intrusive_ptr<cppa::node_id>"
,
"@proc"
},
{
"cppa::io::accept_handle"
,
"@ac_hdl"
},
{
"cppa::io::connection_handle"
,
"@cn_hdl"
},
{
"cppa::message_header"
,
"@header"
},
{
"cppa::sync_timeout_msg"
,
"@sync_timeout"
},
{
"cppa::timeout_msg"
,
"@timeout"
},
{
"cppa::unit_t"
,
"@0"
},
{
"cppa::util::buffer"
,
"@buffer"
},
{
"cppa::util::duration"
,
"@duration"
},
...
...
@@ -92,7 +96,8 @@ namespace cppa { namespace detail {
{
"std::basic_string<@u32,std::char_traits<@u32>,std::allocator<@u32>>"
,
"@u32str"
},
// std::map<std::string,std::string>
{
"std::map<@str,@str,std::less<@str>,std::allocator<std::pair<const @str,@str>>>"
,
{
"std::map<@str,@str,std::less<@str>,"
"std::allocator<std::pair<const @str,@str>>>"
,
"@strmap"
}
};
...
...
@@ -372,6 +377,38 @@ inline void deserialize_impl(bool& val, deserializer* source) {
val
=
source
->
read
<
uint8_t
>
()
!=
0
;
}
// exit_msg & down_msg have the same fields
template
<
typename
T
>
typename
std
::
enable_if
<
std
::
is_same
<
T
,
down_msg
>::
value
||
std
::
is_same
<
T
,
exit_msg
>::
value
>::
type
serialize_impl
(
const
T
&
dm
,
serializer
*
sink
)
{
serialize_impl
(
dm
.
source
,
sink
);
sink
->
write_value
(
dm
.
reason
);
}
// exit_msg & down_msg have the same fields
template
<
typename
T
>
typename
std
::
enable_if
<
std
::
is_same
<
T
,
down_msg
>::
value
||
std
::
is_same
<
T
,
exit_msg
>::
value
>::
type
deserialize_impl
(
T
&
dm
,
deserializer
*
source
)
{
deserialize_impl
(
dm
.
source
,
source
);
dm
.
reason
=
source
->
read
<
std
::
uint32_t
>
();
}
inline
void
serialize_impl
(
const
timeout_msg
&
tm
,
serializer
*
sink
)
{
sink
->
write_value
(
tm
.
timeout_id
);
}
inline
void
deserialize_impl
(
timeout_msg
&
tm
,
deserializer
*
source
)
{
tm
.
timeout_id
=
source
->
read
<
std
::
uint32_t
>
();
}
inline
void
serialize_impl
(
const
sync_timeout_msg
&
,
serializer
*
)
{
}
inline
void
deserialize_impl
(
const
sync_timeout_msg
&
,
deserializer
*
)
{
}
bool
types_equal
(
const
std
::
type_info
*
lhs
,
const
std
::
type_info
*
rhs
)
{
// in some cases (when dealing with dynamic libraries),
// address can be different although types are equal
...
...
@@ -711,37 +748,41 @@ class utim_impl : public uniform_type_info_map {
size_t
,
ptrdiff_t
,
intptr_t
>
(
mapping
);
// fill builtin types *in sorted order* (by uniform name)
size_t
i
=
0
;
m_builtin_types
[
i
++
]
=
&
m_type_unit
;
// @0
m_builtin_types
[
i
++
]
=
&
m_ac_hdl
;
// @ac_hdl
m_builtin_types
[
i
++
]
=
&
m_type_actor
;
// @actor
m_builtin_types
[
i
++
]
=
&
m_type_actor_addr
;
// @actor_addr
m_builtin_types
[
i
++
]
=
&
m_type_atom
;
// @atom
m_builtin_types
[
i
++
]
=
&
m_type_buffer
;
// @buffer
m_builtin_types
[
i
++
]
=
&
m_type_channel
;
// @channel
m_builtin_types
[
i
++
]
=
&
m_cn_hdl
;
// @cn_hdl
m_builtin_types
[
i
++
]
=
&
m_type_duration
;
// @duration
m_builtin_types
[
i
++
]
=
&
m_type_group
;
// @group
m_builtin_types
[
i
++
]
=
&
m_type_header
;
// @header
m_builtin_types
[
i
++
]
=
&
m_type_i16
;
// @i16
m_builtin_types
[
i
++
]
=
&
m_type_i32
;
// @i32
m_builtin_types
[
i
++
]
=
&
m_type_i64
;
// @i64
m_builtin_types
[
i
++
]
=
&
m_type_i8
;
// @i8
m_builtin_types
[
i
++
]
=
&
m_type_long_double
;
// @ldouble
m_builtin_types
[
i
++
]
=
&
m_type_proc
;
// @proc
m_builtin_types
[
i
++
]
=
&
m_type_str
;
// @str
m_builtin_types
[
i
++
]
=
&
m_type_strmap
;
// @strmap
m_builtin_types
[
i
++
]
=
&
m_type_tuple
;
// @tuple
m_builtin_types
[
i
++
]
=
&
m_type_u16
;
// @u16
m_builtin_types
[
i
++
]
=
&
m_type_u16str
;
// @u16str
m_builtin_types
[
i
++
]
=
&
m_type_u32
;
// @u32
m_builtin_types
[
i
++
]
=
&
m_type_u32str
;
// @u32str
m_builtin_types
[
i
++
]
=
&
m_type_u64
;
// @u64
m_builtin_types
[
i
++
]
=
&
m_type_u8
;
// @u8
m_builtin_types
[
i
++
]
=
&
m_type_bool
;
// bool
m_builtin_types
[
i
++
]
=
&
m_type_double
;
// double
m_builtin_types
[
i
++
]
=
&
m_type_float
;
// float
CPPA_REQUIRE
(
i
==
m_builtin_types
.
size
());
auto
i
=
m_builtin_types
.
begin
();
*
i
++
=
&
m_type_unit
;
// @0
*
i
++
=
&
m_ac_hdl
;
// @ac_hdl
*
i
++
=
&
m_type_actor
;
// @actor
*
i
++
=
&
m_type_actor_addr
;
// @actor_addr
*
i
++
=
&
m_type_atom
;
// @atom
*
i
++
=
&
m_type_buffer
;
// @buffer
*
i
++
=
&
m_type_channel
;
// @channel
*
i
++
=
&
m_cn_hdl
;
// @cn_hdl
*
i
++
=
&
m_type_down_msg
;
// @down
*
i
++
=
&
m_type_duration
;
// @duration
*
i
++
=
&
m_type_exit_msg
;
// @exit
*
i
++
=
&
m_type_group
;
// @group
*
i
++
=
&
m_type_header
;
// @header
*
i
++
=
&
m_type_i16
;
// @i16
*
i
++
=
&
m_type_i32
;
// @i32
*
i
++
=
&
m_type_i64
;
// @i64
*
i
++
=
&
m_type_i8
;
// @i8
*
i
++
=
&
m_type_long_double
;
// @ldouble
*
i
++
=
&
m_type_proc
;
// @proc
*
i
++
=
&
m_type_str
;
// @str
*
i
++
=
&
m_type_strmap
;
// @strmap
*
i
++
=
&
m_type_sync_timeout
;
// @sync_timeout
*
i
++
=
&
m_type_timeout
;
// @timeout
*
i
++
=
&
m_type_tuple
;
// @tuple
*
i
++
=
&
m_type_u16
;
// @u16
*
i
++
=
&
m_type_u16str
;
// @u16str
*
i
++
=
&
m_type_u32
;
// @u32
*
i
++
=
&
m_type_u32str
;
// @u32str
*
i
++
=
&
m_type_u64
;
// @u64
*
i
++
=
&
m_type_u8
;
// @u8
*
i
++
=
&
m_type_bool
;
// bool
*
i
++
=
&
m_type_double
;
// double
*
i
++
=
&
m_type_float
;
// float
CPPA_REQUIRE
(
i
==
m_builtin_types
.
end
());
# if CPPA_DEBUG_MODE
auto
cmp
=
[](
pointer
lhs
,
pointer
rhs
)
{
return
strcmp
(
lhs
->
name
(),
rhs
->
name
())
<
0
;
...
...
@@ -834,22 +875,31 @@ class utim_impl : public uniform_type_info_map {
typedef
std
::
map
<
std
::
string
,
std
::
string
>
strmap
;
// 0-9
uti_impl
<
node_id_ptr
>
m_type_proc
;
uti_impl
<
io
::
accept_handle
>
m_ac_hdl
;
uti_impl
<
io
::
connection_handle
>
m_cn_hdl
;
uti_impl
<
channel
>
m_type_channel
;
uti_impl
<
down_msg
>
m_type_down_msg
;
uti_impl
<
exit_msg
>
m_type_exit_msg
;
buffer_type_info_impl
m_type_buffer
;
uti_impl
<
actor
>
m_type_actor
;
uti_impl
<
actor_addr
>
m_type_actor_addr
;
uti_impl
<
group_ptr
>
m_type_group
;
// 10-19
uti_impl
<
any_tuple
>
m_type_tuple
;
uti_impl
<
util
::
duration
>
m_type_duration
;
uti_impl
<
sync_timeout_msg
>
m_type_sync_timeout
;
uti_impl
<
timeout_msg
>
m_type_timeout
;
uti_impl
<
message_header
>
m_type_header
;
uti_impl
<
unit_t
>
m_type_unit
;
uti_impl
<
atom_value
>
m_type_atom
;
uti_impl
<
std
::
string
>
m_type_str
;
uti_impl
<
std
::
u16string
>
m_type_u16str
;
uti_impl
<
std
::
u32string
>
m_type_u32str
;
// 20-29
default_uniform_type_info_impl
<
strmap
>
m_type_strmap
;
uti_impl
<
bool
>
m_type_bool
;
uti_impl
<
float
>
m_type_float
;
...
...
@@ -860,12 +910,14 @@ class utim_impl : public uniform_type_info_map {
int_tinfo
<
std
::
int16_t
>
m_type_i16
;
int_tinfo
<
std
::
uint16_t
>
m_type_u16
;
int_tinfo
<
std
::
int32_t
>
m_type_i32
;
// 30-32
int_tinfo
<
std
::
uint32_t
>
m_type_u32
;
int_tinfo
<
std
::
int64_t
>
m_type_i64
;
int_tinfo
<
std
::
uint64_t
>
m_type_u64
;
// both containers are sorted by uniform name
std
::
array
<
pointer
,
29
>
m_builtin_types
;
std
::
array
<
pointer
,
33
>
m_builtin_types
;
std
::
vector
<
uniform_type_info
*>
m_user_types
;
mutable
util
::
shared_spinlock
m_lock
;
...
...
unit_testing/test_broker.cpp
View file @
8d1b0361
...
...
@@ -71,8 +71,8 @@ void pong(cppa::untyped_actor* self) {
on
(
atom
(
"ping"
),
arg_match
)
>>
[](
int
value
)
{
return
make_cow_tuple
(
atom
(
"pong"
),
value
);
},
on
(
atom
(
"DOWN"
),
arg_match
)
>>
[
=
](
uint32_t
reason
)
{
self
->
quit
(
reason
);
on
_arg_match
>>
[
=
](
const
down_msg
&
dm
)
{
self
->
quit
(
dm
.
reason
);
},
others
()
>>
CPPA_UNEXPECTED_MSG_CB
()
);
...
...
@@ -113,8 +113,8 @@ void peer(io::broker* self, io::connection_handle hdl, const actor& buddy) {
on
(
atom
(
"pong"
),
arg_match
)
>>
[
=
](
int
value
)
{
write
(
atom
(
"pong"
),
value
);
},
on
(
atom
(
"DOWN"
),
arg_match
)
>>
[
=
](
uint32_t
reason
)
{
if
(
self
->
last_sender
()
==
buddy
)
self
->
quit
(
reason
);
on
_arg_match
>>
[
=
](
const
down_msg
&
dm
)
{
if
(
dm
.
source
==
buddy
)
self
->
quit
(
dm
.
reason
);
},
others
()
>>
CPPA_UNEXPECTED_MSG_CB
()
);
...
...
unit_testing/test_remote_actor.cpp
View file @
8d1b0361
...
...
@@ -69,8 +69,8 @@ void spawn5_server_impl(untyped_actor* self, actor client, group_ptr grp) {
CPPA_PRINT
(
"wait for DOWN messages"
);
auto
downs
=
std
::
make_shared
<
int
>
(
0
);
self
->
become
(
on
(
atom
(
"DOWN"
),
arg_match
)
>>
[
=
](
std
::
uint32_t
reason
)
{
if
(
reason
!=
exit_reason
::
normal
)
{
on
_arg_match
>>
[
=
](
const
down_msg
&
dm
)
{
if
(
dm
.
reason
!=
exit_reason
::
normal
)
{
CPPA_PRINTERR
(
"reflector exited for non-normal exit reason!"
);
}
if
(
++*
downs
==
5
)
{
...
...
@@ -141,8 +141,8 @@ void spawn5_client(untyped_actor* self) {
template
<
typename
F
>
void
await_down
(
untyped_actor
*
self
,
actor
ptr
,
F
continuation
)
{
self
->
become
(
on
(
atom
(
"DOWN"
),
arg_match
)
>>
[
=
](
uint32_t
)
->
bool
{
if
(
self
->
last_sender
()
==
ptr
)
{
on
_arg_match
>>
[
=
](
const
down_msg
&
dm
)
->
bool
{
if
(
dm
.
source
==
ptr
)
{
continuation
();
return
true
;
}
...
...
@@ -351,9 +351,9 @@ int main(int argc, char** argv) {
}
auto
c
=
self
->
spawn
<
client
,
monitored
>
(
serv
);
self
->
receive
(
on
(
atom
(
"DOWN"
),
arg_match
)
>>
[
&
](
uint32_t
rsn
)
{
CPPA_CHECK_EQUAL
(
self
->
last_sender
()
,
c
);
CPPA_CHECK_EQUAL
(
rs
n
,
exit_reason
::
normal
);
on
_arg_match
>>
[
&
](
const
down_msg
&
dm
)
{
CPPA_CHECK_EQUAL
(
dm
.
source
,
c
);
CPPA_CHECK_EQUAL
(
dm
.
reaso
n
,
exit_reason
::
normal
);
}
);
});
...
...
@@ -397,9 +397,9 @@ int main(int argc, char** argv) {
else
{
CPPA_PRINT
(
"actor published at port "
<<
port
);
}
CPPA_CHECKPOINT
();
self
->
receive
(
on
(
atom
(
"DOWN"
),
arg_match
)
>>
[
&
](
uint32_t
rsn
)
{
CPPA_CHECK_EQUAL
(
self
->
last_sender
()
,
serv
);
CPPA_CHECK_EQUAL
(
rs
n
,
exit_reason
::
normal
);
on
_arg_match
>>
[
&
](
const
down_msg
&
dm
)
{
CPPA_CHECK_EQUAL
(
dm
.
source
,
serv
);
CPPA_CHECK_EQUAL
(
dm
.
reaso
n
,
exit_reason
::
normal
);
}
);
// wait until separate process (in sep. thread) finished execution
...
...
unit_testing/test_spawn.cpp
View file @
8d1b0361
...
...
@@ -529,7 +529,12 @@ void test_spawn() {
);
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
self
->
receive
(
on
(
atom
(
"DOWN"
),
exit_reason
::
user_shutdown
)
>>
CPPA_CHECKPOINT_CB
(),
on_arg_match
>>
[
&
](
const
down_msg
&
dm
)
{
if
(
dm
.
reason
==
exit_reason
::
user_shutdown
)
{
CPPA_CHECKPOINT
();
}
else
{
CPPA_UNEXPECTED_MSG
();
}
},
others
()
>>
CPPA_UNEXPECTED_MSG_CB
()
);
self
->
await_all_other_actors_done
();
...
...
@@ -545,7 +550,12 @@ void test_spawn() {
);
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
self
->
receive
(
on
(
atom
(
"DOWN"
),
exit_reason
::
user_shutdown
)
>>
CPPA_CHECKPOINT_CB
(),
on_arg_match
>>
[
&
](
const
down_msg
&
dm
)
{
if
(
dm
.
reason
==
exit_reason
::
user_shutdown
)
{
CPPA_CHECKPOINT
();
}
else
{
CPPA_UNEXPECTED_MSG
();
}
},
others
()
>>
CPPA_UNEXPECTED_MSG_CB
()
);
self
->
await_all_other_actors_done
();
...
...
@@ -562,7 +572,12 @@ void test_spawn() {
);
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
self
->
receive
(
on
(
atom
(
"DOWN"
),
exit_reason
::
user_shutdown
)
>>
CPPA_CHECKPOINT_CB
(),
on_arg_match
>>
[
&
](
const
down_msg
&
dm
)
{
if
(
dm
.
reason
==
exit_reason
::
user_shutdown
)
{
CPPA_CHECKPOINT
();
}
else
{
CPPA_UNEXPECTED_MSG
();
}
},
others
()
>>
CPPA_UNEXPECTED_MSG_CB
()
);
self
->
await_all_other_actors_done
();
...
...
@@ -714,8 +729,9 @@ void test_spawn() {
after
(
std
::
chrono
::
seconds
(
5
))
>>
CPPA_UNEXPECTED_TOUT_CB
()
);
self
->
receive
(
on
(
atom
(
"DOWN"
),
exit_reason
::
normal
)
>>
[
&
]
{
CPPA_CHECK_EQUAL
(
self
->
last_sender
(),
sync_testee
);
on_arg_match
>>
[
&
](
const
down_msg
&
dm
)
{
CPPA_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
normal
);
CPPA_CHECK_EQUAL
(
dm
.
source
,
sync_testee
);
}
);
self
->
await_all_other_actors_done
();
...
...
@@ -830,20 +846,19 @@ void test_spawn() {
self
->
delayed_send
(
self
,
chrono
::
seconds
(
1
),
atom
(
"FooBar"
));
// wait for DOWN and EXIT messages of pong
self
->
receive_for
(
i
,
4
)
(
on
(
atom
(
"EXIT"
),
arg_match
)
>>
[
&
](
uint32_t
reason
)
{
CPPA_CHECK_EQUAL
(
e
xit_reason
::
user_shutdown
,
reason
);
CPPA_CHECK
(
self
->
last_sender
()
==
pong_actor
);
on
_arg_match
>>
[
&
](
const
exit_msg
&
em
)
{
CPPA_CHECK_EQUAL
(
e
m
.
source
,
pong_actor
);
CPPA_CHECK
_EQUAL
(
em
.
reason
,
exit_reason
::
user_shutdown
);
flags
|=
0x01
;
},
on
(
atom
(
"DOWN"
),
arg_match
)
>>
[
&
](
uint32_t
reason
)
{
auto
who
=
self
->
last_sender
();
if
(
who
==
pong_actor
)
{
on_arg_match
>>
[
&
](
const
down_msg
&
dm
)
{
if
(
dm
.
source
==
pong_actor
)
{
flags
|=
0x02
;
CPPA_CHECK_EQUAL
(
reason
,
exit_reason
::
user_shutdown
);
CPPA_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
user_shutdown
);
}
else
if
(
who
==
ping_actor
)
{
else
if
(
dm
.
source
==
ping_actor
)
{
flags
|=
0x04
;
CPPA_CHECK_EQUAL
(
reason
,
exit_reason
::
normal
);
CPPA_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
normal
);
}
},
on_arg_match
>>
[
&
](
const
atom_value
&
val
)
{
...
...
unit_testing/test_sync_send.cpp
View file @
8d1b0361
...
...
@@ -201,7 +201,9 @@ void test_sync_send() {
self
->
quit
(
exit_reason
::
user_shutdown
);
});
self
->
receive
(
on
(
atom
(
"DOWN"
),
exit_reason
::
user_shutdown
)
>>
CPPA_CHECKPOINT_CB
(),
on_arg_match
>>
[
&
](
const
down_msg
&
dm
)
{
CPPA_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
user_shutdown
);
},
others
()
>>
CPPA_UNEXPECTED_MSG_CB
()
);
auto
mirror
=
spawn
<
sync_mirror
>
();
...
...
@@ -219,9 +221,12 @@ void test_sync_send() {
self
->
receive
(
on
(
atom
(
"success"
))
>>
CPPA_CHECKPOINT_CB
(),
on
(
atom
(
"failure"
))
>>
CPPA_FAILURE_CB
(
"A didn't receive sync response"
),
on
(
atom
(
"DOWN"
),
arg_match
).
when
(
_x2
!=
exit_reason
::
normal
)
>>
[
&
](
uint32_t
err
)
{
CPPA_FAILURE
(
"A exited for reason "
<<
err
);
on_arg_match
>>
[
&
](
const
down_msg
&
dm
)
->
match_hint
{
if
(
dm
.
reason
!=
exit_reason
::
normal
)
{
CPPA_FAILURE
(
"A exited for reason "
<<
dm
.
reason
);
return
match_hint
::
handle
;
}
return
match_hint
::
skip
;
}
);
};
...
...
@@ -235,14 +240,16 @@ void test_sync_send() {
self
->
await_all_other_actors_done
();
CPPA_CHECKPOINT
();
self
->
timed_sync_send
(
self
,
std
::
chrono
::
milliseconds
(
50
),
atom
(
"NoWay"
)).
await
(
on
(
atom
(
"TIMEOUT"
)
)
>>
CPPA_CHECKPOINT_CB
(),
on
<
sync_timeout_msg
>
(
)
>>
CPPA_CHECKPOINT_CB
(),
others
()
>>
CPPA_UNEXPECTED_MSG_CB
()
);
// we should have received two DOWN messages with normal exit reason
// plus 'NoWay'
int
i
=
0
;
self
->
receive_for
(
i
,
3
)
(
on
(
atom
(
"DOWN"
),
exit_reason
::
normal
)
>>
CPPA_CHECKPOINT_CB
(),
on_arg_match
>>
[
&
](
const
down_msg
&
dm
)
{
CPPA_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
normal
);
},
on
(
atom
(
"NoWay"
))
>>
[]
{
CPPA_CHECKPOINT
();
CPPA_PRINT
(
"trigger
\"
actor did not reply to a "
...
...
@@ -305,7 +312,9 @@ void test_sync_send() {
self
->
receive_loop
(
others
()
>>
CPPA_UNEXPECTED_MSG_CB
());
});
self
->
receive
(
on
(
atom
(
"DOWN"
),
exit_reason
::
user_shutdown
)
>>
CPPA_CHECKPOINT_CB
(),
on_arg_match
>>
[
&
](
const
down_msg
&
dm
)
{
CPPA_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
user_shutdown
);
},
others
()
>>
CPPA_UNEXPECTED_MSG_CB
()
);
}
...
...
unit_testing/test_uniform_type.cpp
View file @
8d1b0361
...
...
@@ -93,7 +93,11 @@ int main() {
"@proc"
,
// intrusive_ptr<node_id>
"@duration"
,
// util::duration
"@buffer"
,
// util::buffer
// default announced cpap tuples
"@down"
,
// down_msg
"@exit"
,
// exit_msg
"@timeout"
,
// timeout_msg
"@sync_timeout"
,
// sync_timeout_msg
// default announced cppa tuples
"@<>+@atom"
,
// {atom_value}
"@<>+@atom+@actor"
,
// {atom_value, actor_ptr}
"@<>+@atom+@proc"
,
// {atom_value, node_id}
...
...
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