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
d375ddf3
Commit
d375ddf3
authored
Oct 18, 2016
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let spawn_server return a pair over actor and port
parent
f304cfdb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
38 deletions
+22
-38
examples/broker/simple_broker.cpp
examples/broker/simple_broker.cpp
+5
-5
examples/broker/simple_http_broker.cpp
examples/broker/simple_http_broker.cpp
+7
-5
libcaf_io/caf/io/middleman.hpp
libcaf_io/caf/io/middleman.hpp
+4
-22
libcaf_io/test/triggering.cpp
libcaf_io/test/triggering.cpp
+6
-6
No files found.
examples/broker/simple_broker.cpp
View file @
d375ddf3
...
@@ -192,14 +192,14 @@ public:
...
@@ -192,14 +192,14 @@ public:
void
run_server
(
actor_system
&
system
,
const
config
&
cfg
)
{
void
run_server
(
actor_system
&
system
,
const
config
&
cfg
)
{
cout
<<
"run in server mode"
<<
endl
;
cout
<<
"run in server mode"
<<
endl
;
auto
pong_actor
=
system
.
spawn
(
pong
);
auto
pong_actor
=
system
.
spawn
(
pong
);
auto
server_
actor
=
system
.
middleman
().
spawn_server
(
server
,
cfg
.
port
,
auto
server_
details
=
system
.
middleman
().
spawn_server
(
server
,
cfg
.
port
,
pong_actor
);
pong_actor
);
if
(
!
server_
actor
)
{
if
(
!
server_
details
)
{
std
::
cerr
<<
"failed to spawn server: "
std
::
cerr
<<
"failed to spawn server: "
<<
system
.
render
(
server_
actor
.
error
())
<<
endl
;
<<
system
.
render
(
server_
details
.
error
())
<<
endl
;
return
;
return
;
}
}
print_on_exit
(
*
server_actor
,
"server"
);
print_on_exit
(
server_details
->
first
,
"server"
);
print_on_exit
(
pong_actor
,
"pong"
);
print_on_exit
(
pong_actor
,
"pong"
);
}
}
...
...
examples/broker/simple_http_broker.cpp
View file @
d375ddf3
...
@@ -77,19 +77,21 @@ public:
...
@@ -77,19 +77,21 @@ public:
};
};
void
caf_main
(
actor_system
&
system
,
const
config
&
cfg
)
{
void
caf_main
(
actor_system
&
system
,
const
config
&
cfg
)
{
auto
server_
actor
=
system
.
middleman
().
spawn_server
(
server
,
cfg
.
port
);
auto
server_
details
=
system
.
middleman
().
spawn_server
(
server
,
cfg
.
port
);
if
(
!
server_
actor
)
{
if
(
!
server_
details
)
{
cerr
<<
"*** cannot spawn server: "
cerr
<<
"*** cannot spawn server: "
<<
system
.
render
(
server_
actor
.
error
())
<<
endl
;
<<
system
.
render
(
server_
details
.
error
())
<<
endl
;
return
;
return
;
}
}
cout
<<
"*** listening on port "
<<
cfg
.
port
<<
endl
;
auto
&
server_actor
=
server_details
->
first
;
auto
&
port
=
server_details
->
second
;
cout
<<
"*** listening on port "
<<
port
<<
endl
;
cout
<<
"*** to quit the program, simply press <enter>"
<<
endl
;
cout
<<
"*** to quit the program, simply press <enter>"
<<
endl
;
// wait for any input
// wait for any input
std
::
string
dummy
;
std
::
string
dummy
;
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
);
}
}
}
// namespace <anonymous>
}
// namespace <anonymous>
...
...
libcaf_io/caf/io/middleman.hpp
View file @
d375ddf3
...
@@ -300,26 +300,8 @@ public:
...
@@ -300,26 +300,8 @@ public:
/// @warning Blocks the caller until the server socket is initialized.
/// @warning Blocks the caller until the server socket is initialized.
template
<
spawn_options
Os
=
no_spawn_options
,
template
<
spawn_options
Os
=
no_spawn_options
,
class
F
=
std
::
function
<
void
(
broker
*
)>,
class
...
Ts
>
class
F
=
std
::
function
<
void
(
broker
*
)>,
class
...
Ts
>
expected
<
typename
infer_handle_from_fun
<
F
>::
type
>
expected
<
std
::
pair
<
typename
infer_handle_from_fun
<
F
>::
type
,
uint16_t
>>
spawn_server
(
F
fun
,
uint16_t
&
port
,
Ts
&&
...
xs
)
{
spawn_server
(
F
fun
,
uint16_t
port
,
Ts
&&
...
xs
)
{
auto
tmp
=
uri
::
make
(
std
::
string
(
default_protocol
)
+
"0.0.0.0:"
+
std
::
to_string
(
port
));
if
(
!
tmp
)
throw
sec
::
invalid_argument
;
std
::
cout
<<
"Built uri '"
<<
tmp
->
str
()
<<
"' from port '"
<<
port
<<
"'. Port was interpreted as '"
<<
tmp
->
port_as_int
()
<<
"'."
<<
std
::
endl
;
using
impl
=
typename
infer_handle_from_fun
<
F
>::
impl
;
return
spawn_server_impl
<
Os
,
impl
>
(
std
::
move
(
fun
),
std
::
move
(
*
tmp
),
std
::
forward
<
Ts
>
(
xs
)...);
}
/// Spawns a new broker as server running on given `port`.
/// @warning Blocks the caller until the server socket is initialized.
template
<
spawn_options
Os
=
no_spawn_options
,
class
F
=
std
::
function
<
void
(
broker
*
)>,
class
...
Ts
>
expected
<
typename
infer_handle_from_fun
<
F
>::
type
>
spawn_server
(
F
fun
,
const
uint16_t
&
port
,
Ts
&&
...
xs
)
{
auto
tmp
=
uri
::
make
(
std
::
string
(
default_protocol
)
+
"0.0.0.0:"
+
auto
tmp
=
uri
::
make
(
std
::
string
(
default_protocol
)
+
"0.0.0.0:"
+
std
::
to_string
(
port
));
std
::
to_string
(
port
));
if
(
!
tmp
)
if
(
!
tmp
)
...
@@ -386,7 +368,7 @@ private:
...
@@ -386,7 +368,7 @@ private:
}
}
template
<
spawn_options
Os
,
class
Impl
,
class
F
,
class
...
Ts
>
template
<
spawn_options
Os
,
class
Impl
,
class
F
,
class
...
Ts
>
expected
<
typename
infer_handle_from_class
<
Impl
>::
type
>
expected
<
std
::
pair
<
typename
infer_handle_from_fun
<
F
>::
type
,
uint16_t
>
>
spawn_server_impl
(
F
fun
,
uri
u
,
Ts
&&
...
xs
)
{
spawn_server_impl
(
F
fun
,
uri
u
,
Ts
&&
...
xs
)
{
detail
::
init_fun_factory
<
Impl
,
F
>
fac
;
detail
::
init_fun_factory
<
Impl
,
F
>
fac
;
auto
init_fun
=
fac
(
std
::
move
(
fun
),
std
::
forward
<
Ts
>
(
xs
)...);
auto
init_fun
=
fac
(
std
::
move
(
fun
),
std
::
forward
<
Ts
>
(
xs
)...);
...
@@ -401,7 +383,7 @@ private:
...
@@ -401,7 +383,7 @@ private:
static_cast
<
abstract_broker
*>
(
ptr
)
->
assign_tcp_doorman
(
hdl
);
static_cast
<
abstract_broker
*>
(
ptr
)
->
assign_tcp_doorman
(
hdl
);
return
init_fun
(
ptr
);
return
init_fun
(
ptr
);
};
};
return
s
ystem
().
spawn_class
<
Impl
,
Os
>
(
cfg
);
return
s
td
::
make_pair
(
system
().
spawn_class
<
Impl
,
Os
>
(
cfg
),
port
);
}
}
expected
<
strong_actor_ptr
>
remote_spawn_impl
(
const
node_id
&
nid
,
expected
<
strong_actor_ptr
>
remote_spawn_impl
(
const
node_id
&
nid
,
...
...
libcaf_io/test/triggering.cpp
View file @
d375ddf3
...
@@ -232,9 +232,9 @@ CAF_TEST_FIXTURE_SCOPE(trigger_tests, fixture)
...
@@ -232,9 +232,9 @@ CAF_TEST_FIXTURE_SCOPE(trigger_tests, fixture)
CAF_TEST
(
trigger_connection
)
{
CAF_TEST
(
trigger_connection
)
{
CAF_MESSAGE
(
"spawn server"
);
CAF_MESSAGE
(
"spawn server"
);
uint16_t
port
=
0
;
auto
server_details
=
server_system
.
middleman
().
spawn_server
(
server1
,
0
)
;
auto
serv
=
server_system
.
middleman
().
spawn_server
(
server1
,
port
);
CAF_REQUIRE
(
server_details
);
CAF_REQUIRE
(
serv
)
;
auto
&
port
=
server_details
->
second
;
CAF_REQUIRE_NOT_EQUAL
(
port
,
0
);
CAF_REQUIRE_NOT_EQUAL
(
port
,
0
);
CAF_MESSAGE
(
"server spawned at port "
<<
port
);
CAF_MESSAGE
(
"server spawned at port "
<<
port
);
std
::
thread
child
{[
&
]
{
std
::
thread
child
{[
&
]
{
...
@@ -246,9 +246,9 @@ CAF_TEST(trigger_connection) {
...
@@ -246,9 +246,9 @@ CAF_TEST(trigger_connection) {
CAF_TEST
(
trigger_acceptor
)
{
CAF_TEST
(
trigger_acceptor
)
{
CAF_MESSAGE
(
"spawn server"
);
CAF_MESSAGE
(
"spawn server"
);
uint16_t
port
=
0
;
auto
server_details
=
server_system
.
middleman
().
spawn_server
(
server2
,
0
)
;
auto
serv
=
server_system
.
middleman
().
spawn_server
(
server2
,
port
);
CAF_REQUIRE
(
server_details
);
CAF_REQUIRE
(
serv
)
;
auto
&
port
=
server_details
->
second
;
CAF_REQUIRE_NOT_EQUAL
(
port
,
0
);
CAF_REQUIRE_NOT_EQUAL
(
port
,
0
);
CAF_MESSAGE
(
"server spawned at port "
<<
port
);
CAF_MESSAGE
(
"server spawned at port "
<<
port
);
std
::
thread
child
{[
&
]
{
std
::
thread
child
{[
&
]
{
...
...
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