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
5e12eb11
Commit
5e12eb11
authored
May 22, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use extract_opts API in more examples
parent
7bc4547c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
42 deletions
+87
-42
examples/brokers/simple_broker.cpp
examples/brokers/simple_broker.cpp
+41
-19
examples/brokers/simple_http_broker.cpp
examples/brokers/simple_http_broker.cpp
+29
-15
examples/remote_actors/group_server.cpp
examples/remote_actors/group_server.cpp
+17
-8
No files found.
examples/brokers/simple_broker.cpp
View file @
5e12eb11
...
@@ -183,26 +183,48 @@ optional<uint16_t> as_u16(const std::string& str) {
...
@@ -183,26 +183,48 @@ optional<uint16_t> as_u16(const std::string& str) {
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
using
std
::
string
;
using
std
::
string
;
message_builder
{
argv
+
1
,
argv
+
argc
}.
apply
({
uint16_t
port
=
0
;
on
(
"-s"
,
as_u16
)
>>
[
&
](
uint16_t
port
)
{
string
host
=
"localhost"
;
auto
res
=
message_builder
(
argv
+
1
,
argv
+
argc
).
extract_opts
({
{
"server,s"
,
"run in server mode"
},
{
"client,c"
,
"run in client mode"
},
{
"port,p"
,
"set port"
,
port
},
{
"host,H"
,
"set host (client mode only"
}
});
if
(
!
res
.
error
.
empty
())
{
cerr
<<
res
.
error
<<
endl
;
return
1
;
}
if
(
res
.
opts
.
count
(
"help"
)
>
0
)
{
cout
<<
res
.
helptext
<<
endl
;
return
0
;
}
if
(
!
res
.
remainder
.
empty
())
{
// not all CLI arguments could be consumed
cerr
<<
"*** too many arguments"
<<
endl
<<
res
.
helptext
<<
endl
;
return
1
;
}
if
(
res
.
opts
.
count
(
"port"
)
==
0
)
{
cerr
<<
"*** no port given"
<<
endl
<<
res
.
helptext
<<
endl
;
return
1
;
}
if
(
res
.
opts
.
count
(
"server"
)
>
0
)
{
cout
<<
"run in server mode"
<<
endl
;
cout
<<
"run in server mode"
<<
endl
;
auto
pong_actor
=
spawn
(
pong
);
auto
pong_actor
=
spawn
(
pong
);
auto
server_actor
=
spawn_io_server
(
server
,
port
,
pong_actor
);
auto
server_actor
=
spawn_io_server
(
server
,
port
,
pong_actor
);
print_on_exit
(
server_actor
,
"server"
);
print_on_exit
(
server_actor
,
"server"
);
print_on_exit
(
pong_actor
,
"pong"
);
print_on_exit
(
pong_actor
,
"pong"
);
},
}
else
if
(
res
.
opts
.
count
(
"client"
)
>
0
)
{
on
(
"-c"
,
val
<
string
>
,
as_u16
)
>>
[
&
](
const
string
&
host
,
uint16_t
port
)
{
auto
ping_actor
=
spawn
(
ping
,
20
);
auto
ping_actor
=
spawn
(
ping
,
20
);
auto
io_actor
=
spawn_io_client
(
broker_impl
,
host
,
port
,
ping_actor
);
auto
io_actor
=
spawn_io_client
(
broker_impl
,
host
,
port
,
ping_actor
);
print_on_exit
(
io_actor
,
"protobuf_io"
);
print_on_exit
(
io_actor
,
"protobuf_io"
);
print_on_exit
(
ping_actor
,
"ping"
);
print_on_exit
(
ping_actor
,
"ping"
);
send_as
(
io_actor
,
ping_actor
,
kickoff_atom
::
value
,
io_actor
);
send_as
(
io_actor
,
ping_actor
,
kickoff_atom
::
value
,
io_actor
);
},
}
else
{
others
>>
[]
{
cerr
<<
"*** neither client nor server mode set"
<<
endl
cerr
<<
"use with eihter '-s PORT' as server or '-c HOST PORT' as client"
<<
res
.
helptext
<<
endl
;
<<
endl
;
return
1
;
}
}
});
await_all_actors_done
();
await_all_actors_done
();
shutdown
();
shutdown
();
}
}
examples/brokers/simple_http_broker.cpp
View file @
5e12eb11
...
@@ -71,9 +71,28 @@ optional<uint16_t> as_u16(const std::string& str) {
...
@@ -71,9 +71,28 @@ optional<uint16_t> as_u16(const std::string& str) {
return
static_cast
<
uint16_t
>
(
stoul
(
str
));
return
static_cast
<
uint16_t
>
(
stoul
(
str
));
}
}
int
main
(
int
argc
,
const
char
**
argv
)
{
int
main
(
int
argc
,
const
char
**
argv
)
{
message_builder
{
argv
+
1
,
argv
+
argc
}.
apply
({
uint16_t
port
=
0
;
on
(
"-p"
,
as_u16
)
>>
[
&
](
uint16_t
port
)
{
auto
res
=
message_builder
(
argv
+
1
,
argv
+
argc
).
extract_opts
({
{
"port,p"
,
"set port"
,
port
},
});
if
(
!
res
.
error
.
empty
())
{
cerr
<<
res
.
error
<<
endl
;
return
1
;
}
if
(
res
.
opts
.
count
(
"help"
)
>
0
)
{
cout
<<
res
.
helptext
<<
endl
;
return
0
;
}
if
(
!
res
.
remainder
.
empty
())
{
// not all CLI arguments could be consumed
cerr
<<
"*** too many arguments"
<<
endl
<<
res
.
helptext
<<
endl
;
return
1
;
}
if
(
res
.
opts
.
count
(
"port"
)
==
0
)
{
cerr
<<
"*** no port given"
<<
endl
<<
res
.
helptext
<<
endl
;
return
1
;
}
cout
<<
"*** run in server mode listen on: "
<<
port
<<
endl
;
cout
<<
"*** run in server mode listen on: "
<<
port
<<
endl
;
cout
<<
"*** to quit the program, simply press <enter>"
<<
endl
;
cout
<<
"*** to quit the program, simply press <enter>"
<<
endl
;
auto
server_actor
=
spawn_io_server
(
server
,
port
);
auto
server_actor
=
spawn_io_server
(
server
,
port
);
...
@@ -82,11 +101,6 @@ int main(int argc, const char **argv) {
...
@@ -82,11 +101,6 @@ int main(int argc, const char **argv) {
std
::
getline
(
std
::
cin
,
dummy
);
std
::
getline
(
std
::
cin
,
dummy
);
// kill server
// kill server
anon_send_exit
(
server_actor
,
exit_reason
::
user_shutdown
);
anon_send_exit
(
server_actor
,
exit_reason
::
user_shutdown
);
},
others
>>
[]
{
cerr
<<
"use with '-p PORT' as server on port"
<<
endl
;
}
});
await_all_actors_done
();
await_all_actors_done
();
shutdown
();
shutdown
();
}
}
examples/remote_actors/group_server.cpp
View file @
5e12eb11
...
@@ -36,15 +36,24 @@ optional<uint16_t> long_port(const string& arg) {
...
@@ -36,15 +36,24 @@ optional<uint16_t> long_port(const string& arg) {
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
uint16_t
port
=
0
;
uint16_t
port
=
0
;
message_builder
{
argv
+
1
,
argv
+
argc
}.
apply
({
auto
res
=
message_builder
(
argv
+
1
,
argv
+
argc
).
extract_opts
({
(
on
(
"-p"
,
to_port
)
||
on
(
long_port
))
>>
[
&
](
uint16_t
arg
)
{
{
"port,p"
,
"set port"
,
port
}
port
=
arg
;
}
});
});
if
(
port
<=
1024
)
{
if
(
!
res
.
error
.
empty
())
{
cerr
<<
"*** no port > 1024 given"
<<
endl
;
cerr
<<
res
.
error
<<
endl
;
cout
<<
"options:"
<<
endl
return
1
;
<<
" -p <arg1> | --port=<arg1> set port"
<<
endl
;
}
if
(
res
.
opts
.
count
(
"help"
)
>
0
)
{
cout
<<
res
.
helptext
<<
endl
;
return
0
;
}
if
(
!
res
.
remainder
.
empty
())
{
// not all CLI arguments could be consumed
cerr
<<
"*** too many arguments"
<<
endl
<<
res
.
helptext
<<
endl
;
return
1
;
}
if
(
res
.
opts
.
count
(
"port"
)
==
0
||
port
<=
1024
)
{
cerr
<<
"*** no valid port (>1024) given"
<<
endl
<<
res
.
helptext
<<
endl
;
return
1
;
return
1
;
}
}
try
{
try
{
...
...
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