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
ff082a26
Commit
ff082a26
authored
Nov 09, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix UB and branch for the '/quit' command
parent
e4ff83c9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
13 deletions
+22
-13
examples/remoting/group_chat.cpp
examples/remoting/group_chat.cpp
+22
-13
No files found.
examples/remoting/group_chat.cpp
View file @
ff082a26
...
...
@@ -45,10 +45,11 @@ behavior client(event_based_actor* self, const std::string& name) {
}
},
[
=
](
join_atom
,
const
group
&
what
)
{
for
(
const
auto
&
g
:
self
->
joined_groups
())
{
std
::
cout
<<
"*** leave "
<<
to_string
(
g
)
<<
std
::
endl
;
self
->
send
(
g
,
name
+
" has left the chatroom"
);
self
->
leave
(
g
);
auto
groups
=
self
->
joined_groups
();
for
(
auto
&&
grp
:
groups
)
{
std
::
cout
<<
"*** leave "
<<
to_string
(
grp
)
<<
std
::
endl
;
self
->
send
(
grp
,
name
+
" has left the chatroom"
);
self
->
leave
(
grp
);
}
std
::
cout
<<
"*** join "
<<
to_string
(
what
)
<<
std
::
endl
;
self
->
join
(
what
);
...
...
@@ -62,20 +63,28 @@ behavior client(event_based_actor* self, const std::string& name) {
[
=
](
const
group_down_msg
&
g
)
{
std
::
cout
<<
"*** chatroom offline: "
<<
to_string
(
g
.
source
)
<<
std
::
endl
;
},
[
=
](
leave_atom
)
{
auto
groups
=
self
->
joined_groups
();
for
(
auto
&&
grp
:
groups
)
{
std
::
cout
<<
"*** leave "
<<
to_string
(
grp
)
<<
std
::
endl
;
self
->
send
(
grp
,
name
+
" has left the chatroom"
);
self
->
leave
(
grp
);
}
},
};
}
class
config
:
public
actor_system_config
{
public:
std
::
string
name
;
std
::
vector
<
std
::
string
>
group_
uri
s
;
std
::
vector
<
std
::
string
>
group_
locator
s
;
uint16_t
port
=
0
;
bool
server_mode
=
false
;
config
()
{
opt_group
{
custom_options_
,
"global"
}
.
add
(
name
,
"name,n"
,
"set name"
)
.
add
(
group_
uri
s
,
"group,g"
,
"join group"
)
.
add
(
group_
locator
s
,
"group,g"
,
"join group"
)
.
add
(
server_mode
,
"server,s"
,
"run in server mode"
)
.
add
(
port
,
"port,p"
,
"set port (ignored in client mode)"
);
}
...
...
@@ -105,13 +114,13 @@ void run_client(actor_system& system, const config& cfg) {
}
}
auto
client_actor
=
system
.
spawn
(
client
,
name
);
for
(
auto
&
uri
:
cfg
.
group_uris
)
{
if
(
auto
grp
=
system
.
groups
().
get
(
uri
))
{
std
::
cout
<<
"*** join "
<<
to_string
(
grp
)
<<
'\n'
;
for
(
auto
&
locator
:
cfg
.
group_locators
)
{
if
(
auto
grp
=
system
.
groups
().
get
(
locator
))
{
anon_send
(
client_actor
,
join_atom_v
,
std
::
move
(
*
grp
));
}
else
{
std
::
cerr
<<
R"(*** failed to parse ")"
<<
uri
<<
R"(" as group URI: )"
<<
to_string
(
grp
.
error
())
<<
std
::
endl
;
std
::
cerr
<<
R"(*** failed to parse ")"
<<
locator
<<
R"(" as group locator: )"
<<
to_string
(
grp
.
error
())
<<
std
::
endl
;
}
}
std
::
cout
<<
"*** starting client, type '/help' for a list of commands
\n
"
;
...
...
@@ -129,7 +138,7 @@ void run_client(actor_system& system, const config& cfg) {
else
std
::
cerr
<<
"*** failed to join group: "
<<
to_string
(
grp
.
error
())
<<
std
::
endl
;
}
else
if
(
words
.
size
()
==
1
&&
words
[
0
]
==
"quit"
)
{
}
else
if
(
words
.
size
()
==
1
&&
words
[
0
]
==
"
/
quit"
)
{
std
::
cin
.
setstate
(
std
::
ios_base
::
eofbit
);
}
else
{
std
::
cout
<<
"*** available commands:
\n
"
...
...
@@ -141,7 +150,7 @@ void run_client(actor_system& system, const config& cfg) {
anon_send
(
client_actor
,
broadcast_atom_v
,
i
->
str
);
}
}
// force actor to quit
anon_send
(
client_actor
,
leave_atom_v
);
anon_send_exit
(
client_actor
,
exit_reason
::
user_shutdown
);
}
...
...
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