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
0af8c8cc
Commit
0af8c8cc
authored
Nov 10, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate review feedback
parent
83788cc4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
29 deletions
+27
-29
examples/remoting/group_chat.cpp
examples/remoting/group_chat.cpp
+19
-21
libcaf_core/caf/detail/group_tunnel.hpp
libcaf_core/caf/detail/group_tunnel.hpp
+1
-1
libcaf_io/caf/detail/remote_group_module.hpp
libcaf_io/caf/detail/remote_group_module.hpp
+1
-1
libcaf_io/src/detail/remote_group_module.cpp
libcaf_io/src/detail/remote_group_module.cpp
+6
-6
No files found.
examples/remoting/group_chat.cpp
View file @
0af8c8cc
...
...
@@ -76,22 +76,18 @@ behavior client(event_based_actor* self, const std::string& name) {
class
config
:
public
actor_system_config
{
public:
std
::
string
name
;
std
::
vector
<
std
::
string
>
group_locators
;
uint16_t
port
=
0
;
bool
server_mode
=
false
;
config
()
{
opt_group
{
custom_options_
,
"global"
}
.
add
(
name
,
"name,n"
,
"set name"
)
.
add
(
group_locators
,
"group,g"
,
"join group"
)
.
add
(
server_mode
,
"server,s"
,
"run in server mode"
)
.
add
(
port
,
"port,p"
,
"set port (ignored in client mode)"
);
.
add
<
std
::
string
>
(
"name,n"
,
"set name"
)
.
add
<
std
::
string
>
(
"group,g"
,
"join group"
)
.
add
<
bool
>
(
"server,s"
,
"run in server mode"
)
.
add
<
uint16_t
>
(
"port,p"
,
"set port (ignored in client mode)"
);
}
};
void
run_server
(
actor_system
&
system
,
const
config
&
cfg
)
{
auto
res
=
system
.
middleman
().
publish_local_groups
(
cfg
.
port
);
void
run_server
(
actor_system
&
sys
)
{
auto
port
=
get_or
(
sys
.
config
(),
"port"
,
uint16_t
{
0
});
auto
res
=
sys
.
middleman
().
publish_local_groups
(
port
);
if
(
!
res
)
{
std
::
cerr
<<
"*** publishing local groups failed: "
<<
to_string
(
res
.
error
())
<<
std
::
endl
;
...
...
@@ -104,8 +100,10 @@ void run_server(actor_system& system, const config& cfg) {
std
::
cout
<<
"... cya"
<<
std
::
endl
;
}
void
run_client
(
actor_system
&
system
,
const
config
&
cfg
)
{
auto
name
=
cfg
.
name
;
void
run_client
(
actor_system
&
sys
)
{
std
::
string
name
;
if
(
auto
config_name
=
get_if
<
std
::
string
>
(
&
sys
.
config
(),
"name"
))
name
=
*
config_name
;
while
(
name
.
empty
())
{
std
::
cout
<<
"please enter your name: "
<<
std
::
flush
;
if
(
!
std
::
getline
(
std
::
cin
,
name
))
{
...
...
@@ -113,12 +111,12 @@ void run_client(actor_system& system, const config& cfg) {
return
;
}
}
auto
client_actor
=
sys
tem
.
spawn
(
client
,
name
);
for
(
auto
&
locator
:
cfg
.
group_locators
)
{
if
(
auto
grp
=
sys
tem
.
groups
().
get
(
locator
))
{
auto
client_actor
=
sys
.
spawn
(
client
,
name
);
if
(
auto
locator
=
get_if
<
std
::
string
>
(
&
sys
.
config
(),
"group"
)
)
{
if
(
auto
grp
=
sys
.
groups
().
get
(
*
locator
))
{
anon_send
(
client_actor
,
join_atom_v
,
std
::
move
(
*
grp
));
}
else
{
std
::
cerr
<<
R"(*** failed to parse ")"
<<
locator
std
::
cerr
<<
R"(*** failed to parse ")"
<<
*
locator
<<
R"(" as group locator: )"
<<
to_string
(
grp
.
error
())
<<
std
::
endl
;
}
...
...
@@ -133,7 +131,7 @@ void run_client(actor_system& system, const config& cfg) {
words
.
clear
();
split
(
words
,
i
->
str
,
is_any_of
(
" "
));
if
(
words
.
size
()
==
3
&&
words
[
0
]
==
"/join"
)
{
if
(
auto
grp
=
sys
tem
.
groups
().
get
(
words
[
1
],
words
[
2
]))
if
(
auto
grp
=
sys
.
groups
().
get
(
words
[
1
],
words
[
2
]))
anon_send
(
client_actor
,
join_atom_v
,
*
grp
);
else
std
::
cerr
<<
"*** failed to join group: "
<<
to_string
(
grp
.
error
())
...
...
@@ -154,9 +152,9 @@ void run_client(actor_system& system, const config& cfg) {
anon_send_exit
(
client_actor
,
exit_reason
::
user_shutdown
);
}
void
caf_main
(
actor_system
&
sys
tem
,
const
config
&
cfg
)
{
auto
f
=
cfg
.
server_mode
?
run_server
:
run_client
;
f
(
sys
tem
,
cfg
);
void
caf_main
(
actor_system
&
sys
,
const
config
&
cfg
)
{
auto
f
=
get_or
(
cfg
,
"server"
,
false
)
?
run_server
:
run_client
;
f
(
sys
);
}
CAF_MAIN
(
id_block
::
group_chat
,
io
::
middleman
)
libcaf_core/caf/detail/group_tunnel.hpp
View file @
0af8c8cc
...
...
@@ -30,7 +30,7 @@
namespace
caf
::
detail
{
/// Represents a group that runs on a
different
CAF node.
/// Represents a group that runs on a
remote
CAF node.
class
CAF_CORE_EXPORT
group_tunnel
:
public
local_group_module
::
impl
{
public:
using
super
=
local_group_module
::
impl
;
...
...
libcaf_io/caf/detail/remote_group_module.hpp
View file @
0af8c8cc
...
...
@@ -63,7 +63,7 @@ private:
return
fun
();
}
//
Removes an instance when connecting it failed
.
//
Stops an instance and removes it from this module
.
void
drop
(
const
group_tunnel_ptr
&
instance
);
// Connects an instance when it is still associated to this module.
...
...
libcaf_io/src/detail/remote_group_module.cpp
View file @
0af8c8cc
...
...
@@ -85,14 +85,14 @@ group_tunnel_ptr remote_group_module::get_impl(actor intermediary,
}
else
{
auto
&
instances
=
nodes_
[
intermediary
.
node
()];
if
(
auto
i
=
instances
.
find
(
group_name
);
i
!=
instances
.
end
())
{
auto
result
=
i
->
second
;
result
->
connect
(
std
::
move
(
intermediary
));
return
result
;
auto
instance
=
i
->
second
;
instance
->
connect
(
std
::
move
(
intermediary
));
return
instance
;
}
else
{
auto
result
=
make_counted
<
detail
::
group_tunnel
>
(
auto
instance
=
make_counted
<
detail
::
group_tunnel
>
(
this
,
group_name
,
std
::
move
(
intermediary
));
instances
.
emplace
(
group_name
,
result
);
return
result
;
instances
.
emplace
(
group_name
,
instance
);
return
instance
;
}
}
});
...
...
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