Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
actor-incubator
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
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-incubator
Commits
98d522e2
Commit
98d522e2
authored
Sep 25, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new middleman class
parent
39ca8e49
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
167 additions
and
9 deletions
+167
-9
libcaf_net/CMakeLists.txt
libcaf_net/CMakeLists.txt
+1
-1
libcaf_net/caf/net/middleman.hpp
libcaf_net/caf/net/middleman.hpp
+79
-0
libcaf_net/src/net/middleman.cpp
libcaf_net/src/net/middleman.cpp
+74
-0
libcaf_net/test/stream_application.cpp
libcaf_net/test/stream_application.cpp
+13
-8
No files found.
libcaf_net/CMakeLists.txt
View file @
98d522e2
...
...
@@ -19,6 +19,7 @@ set(LIBCAF_NET_SRCS
src/ip.cpp
src/message_type.cpp
src/multiplexer.cpp
src/net/middleman.cpp
src/network_socket.cpp
src/pipe_socket.cpp
src/pollset_updater.cpp
...
...
@@ -27,7 +28,6 @@ set(LIBCAF_NET_SRCS
src/stream_socket.cpp
src/tcp_accept_socket.cpp
src/tcp_stream_socket.cpp
src/tcp_stream_socket.cpp
src/udp_datagram_socket.cpp
)
...
...
libcaf_net/caf/net/middleman.hpp
0 → 100644
View file @
98d522e2
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2019 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include <thread>
#include "caf/actor_system.hpp"
#include "caf/net/fwd.hpp"
namespace
caf
{
namespace
net
{
class
middleman
:
public
actor_system
::
module
{
public:
// -- constructors, destructors, and assignment operators --------------------
~
middleman
()
override
;
// -- interface functions ----------------------------------------------------
void
start
()
override
;
void
stop
()
override
;
void
init
(
actor_system_config
&
)
override
;
id_t
id
()
const
override
;
void
*
subtype_ptr
()
override
;
// -- factory functions ------------------------------------------------------
static
actor_system
::
module
*
make
(
actor_system
&
,
detail
::
type_list
<>
);
// -- properties -------------------------------------------------------------
const
actor_system_config
&
config
()
const
noexcept
{
return
sys_
.
config
();
}
const
multiplexer_ptr
&
mpx
()
const
noexcept
{
return
mpx_
;
}
private:
// -- constructors, destructors, and assignment operators --------------------
explicit
middleman
(
actor_system
&
sys
);
// -- member variables -------------------------------------------------------
/// Points to the parent system.
actor_system
&
sys_
;
/// Stores the global socket I/O multiplexer.
multiplexer_ptr
mpx_
;
/// Runs the multiplexer's event loop
std
::
thread
mpx_thread_
;
};
}
// namespace net
}
// namespace caf
libcaf_net/src/net/middleman.cpp
0 → 100644
View file @
98d522e2
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2019 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/net/middleman.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/net/multiplexer.hpp"
#include "caf/raise_error.hpp"
#include "caf/uri.hpp"
namespace
caf
{
namespace
net
{
middleman
::
middleman
(
actor_system
&
sys
)
:
sys_
(
sys
)
{
mpx_
=
std
::
make_shared
<
multiplexer
>
();
}
middleman
::~
middleman
()
{
// nop
}
void
middleman
::
start
()
{
if
(
!
get_or
(
config
(),
"middleman.manual-multiplexing"
,
false
))
{
auto
mpx
=
mpx_
;
mpx_thread_
=
std
::
thread
{[
mpx
]
{
mpx
->
run
();
}};
}
}
void
middleman
::
stop
()
{
mpx_
->
close_pipe
();
if
(
mpx_thread_
.
joinable
())
mpx_thread_
.
join
();
}
void
middleman
::
init
(
actor_system_config
&
cfg
)
{
if
(
auto
err
=
mpx_
->
init
())
CAF_RAISE_ERROR
(
"mpx->init failed"
);
if
(
auto
node_uri
=
get_if
<
uri
>
(
&
cfg
,
"middleman.this-node"
))
{
auto
this_node
=
make_node_id
(
std
::
move
(
*
node_uri
));
sys_
.
node_
.
swap
(
this_node
);
}
else
{
CAF_RAISE_ERROR
(
"no valid entry for middleman.this-node found"
);
}
}
actor_system
::
module
::
id_t
middleman
::
id
()
const
{
return
module
::
network_manager
;
}
void
*
middleman
::
subtype_ptr
()
{
return
this
;
}
actor_system
::
module
*
middleman
::
make
(
actor_system
&
sys
,
detail
::
type_list
<>
)
{
return
new
middleman
(
sys
);
}
}
// namespace net
}
// namespace caf
libcaf_net/test/stream_application.cpp
View file @
98d522e2
...
...
@@ -33,6 +33,7 @@
#include "caf/net/basp/constants.hpp"
#include "caf/net/basp/ec.hpp"
#include "caf/net/make_endpoint_manager.hpp"
#include "caf/net/middleman.hpp"
#include "caf/net/multiplexer.hpp"
#include "caf/net/stream_socket.hpp"
#include "caf/net/stream_transport.hpp"
...
...
@@ -58,26 +59,31 @@ size_t fetch_size(variant<size_t, sec> x) {
return
get
<
size_t
>
(
x
);
}
struct
fixture
:
test_coordinator_fixture
<>
,
struct
config
:
actor_system_config
{
config
()
{
put
(
content
,
"middleman.this-node"
,
unbox
(
make_uri
(
"test:earth"
)));
load
<
middleman
>
();
}
};
struct
fixture
:
test_coordinator_fixture
<
config
>
,
host_fixture
,
proxy_registry
::
backend
{
fixture
()
{
uri
mars_uri
;
REQUIRE_OK
(
parse
(
"t
cp://
mars"
,
mars_uri
));
REQUIRE_OK
(
parse
(
"t
est:
mars"
,
mars_uri
));
mars
=
make_node_id
(
mars_uri
);
mpx
=
std
::
make_shared
<
multiplexer
>
();
if
(
auto
err
=
mpx
->
init
())
CAF_FAIL
(
"mpx->init failed: "
<<
sys
.
render
(
err
));
auto
proxies
=
std
::
make_shared
<
proxy_registry
>
(
sys
,
*
this
);
auto
sockets
=
unbox
(
make_stream_socket_pair
());
sock
=
sockets
.
first
;
nonblocking
(
sockets
.
first
,
true
);
nonblocking
(
sockets
.
second
,
true
);
auto
mpx
=
sys
.
network_manager
().
mpx
();
mgr
=
make_endpoint_manager
(
mpx
,
sys
,
transport_type
{
sockets
.
second
,
basp
::
application
{
proxies
}});
REQUIRE_OK
(
mgr
->
init
());
mpx
->
handle_updates
();
handle_io_event
();
CAF_CHECK_EQUAL
(
mpx
->
num_socket_managers
(),
2u
);
auto
&
dref
=
dynamic_cast
<
endpoint_manager_impl
<
transport_type
>&>
(
*
mgr
);
app
=
&
dref
.
application
();
...
...
@@ -88,6 +94,7 @@ struct fixture : test_coordinator_fixture<>,
}
bool
handle_io_event
()
override
{
auto
mpx
=
sys
.
network_manager
().
mpx
();
mpx
->
handle_updates
();
return
mpx
->
poll_once
(
false
);
}
...
...
@@ -157,8 +164,6 @@ struct fixture : test_coordinator_fixture<>,
node_id
mars
;
multiplexer_ptr
mpx
;
endpoint_manager_ptr
mgr
;
stream_socket
sock
;
...
...
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