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
3cd6dd58
Commit
3cd6dd58
authored
May 31, 2020
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for tcp_backend
parent
1d1cfef7
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
128 additions
and
4 deletions
+128
-4
libcaf_net/CMakeLists.txt
libcaf_net/CMakeLists.txt
+1
-0
libcaf_net/caf/net/backend/tcp.hpp
libcaf_net/caf/net/backend/tcp.hpp
+1
-2
libcaf_net/caf/net/middleman.hpp
libcaf_net/caf/net/middleman.hpp
+4
-0
libcaf_net/caf/net/middleman_backend.hpp
libcaf_net/caf/net/middleman_backend.hpp
+3
-0
libcaf_net/src/net/backend/tcp.cpp
libcaf_net/src/net/backend/tcp.cpp
+5
-2
libcaf_net/src/net/middleman.cpp
libcaf_net/src/net/middleman.cpp
+20
-0
libcaf_net/test/net/backend/tcp.cpp
libcaf_net/test/net/backend/tcp.cpp
+94
-0
No files found.
libcaf_net/CMakeLists.txt
View file @
3cd6dd58
...
...
@@ -148,4 +148,5 @@ caf_incubator_add_test_suites(caf-net-test
transport_worker_dispatcher
udp_datagram_socket
network_socket
net.backend.tcp
)
libcaf_net/caf/net/backend/tcp.hpp
View file @
3cd6dd58
...
...
@@ -49,7 +49,7 @@ public:
void
stop
()
override
;
endpoint_manager_ptr
connect
(
const
uri
&
locator
);
endpoint_manager_ptr
connect
(
const
uri
&
locator
)
override
;
endpoint_manager_ptr
peer
(
const
node_id
&
id
)
override
;
...
...
@@ -79,7 +79,6 @@ private:
using
application_type
=
basp
::
application
;
basp_application_factory
(
proxy_registry
&
proxies
);
~
basp_application_factory
();
template
<
class
Parent
>
error
init
(
Parent
&
)
{
...
...
libcaf_net/caf/net/middleman.hpp
View file @
3cd6dd58
...
...
@@ -76,6 +76,8 @@ public:
// -- remoting ---------------------------------------------------------------
expected
<
endpoint_manager_ptr
>
connect
(
const
uri
&
locator
);
// Publishes an actor.
template
<
class
Handle
=
actor
>
error
publish
(
Handle
whom
,
const
uri
&
locator
)
{
...
...
@@ -124,6 +126,8 @@ public:
middleman_backend
*
backend
(
string_view
scheme
)
const
noexcept
;
expected
<
uint16_t
>
port
(
string_view
scheme
)
const
;
private:
// -- constructors, destructors, and assignment operators --------------------
...
...
libcaf_net/caf/net/middleman_backend.hpp
View file @
3cd6dd58
...
...
@@ -46,6 +46,9 @@ public:
/// @returns The endpoint manager for `peer` on success, `nullptr` otherwise.
virtual
endpoint_manager_ptr
peer
(
const
node_id
&
id
)
=
0
;
/// Establishes a connection to a remote node.
virtual
endpoint_manager_ptr
connect
(
const
uri
&
locator
)
=
0
;
/// Publishes an actor.
virtual
void
publish
(
actor
handle
,
const
uri
&
locator
)
=
0
;
...
...
libcaf_net/src/net/backend/tcp.cpp
View file @
3cd6dd58
...
...
@@ -64,7 +64,6 @@ error tcp::init() {
auto
doorman_uri
=
make_uri
(
"tcp://doorman"
);
if
(
!
doorman_uri
)
return
doorman_uri
.
error
();
;
auto
&
mpx
=
mm_
.
mpx
();
auto
mgr
=
make_endpoint_manager
(
mpx
,
mm_
.
system
(),
...
...
@@ -73,7 +72,6 @@ error tcp::init() {
CAF_LOG_ERROR
(
"mgr->init() failed: "
<<
err
);
return
err
;
}
mpx
->
register_reading
(
mgr
);
return
none
;
}
...
...
@@ -135,4 +133,9 @@ endpoint_manager_ptr tcp::get_peer(const node_id& id) {
return
nullptr
;
}
tcp
::
basp_application_factory
::
basp_application_factory
(
proxy_registry
&
proxies
)
:
proxies_
(
proxies
)
{
// nop
}
}
// namespace caf::net::backend
libcaf_net/src/net/middleman.cpp
View file @
3cd6dd58
...
...
@@ -20,11 +20,14 @@
#include "caf/actor_system_config.hpp"
#include "caf/detail/set_thread_name.hpp"
#include "caf/expected.hpp"
#include "caf/init_global_meta_objects.hpp"
#include "caf/net/basp/ec.hpp"
#include "caf/net/endpoint_manager.hpp"
#include "caf/net/middleman_backend.hpp"
#include "caf/net/multiplexer.hpp"
#include "caf/raise_error.hpp"
#include "caf/sec.hpp"
#include "caf/send.hpp"
#include "caf/uri.hpp"
...
...
@@ -83,6 +86,7 @@ void middleman::init(actor_system_config& cfg) {
CAF_LOG_ERROR
(
"failed to initialize backend: "
<<
err
);
CAF_RAISE_ERROR
(
"failed to initialize backend"
);
}
std
::
cout
<<
"init"
<<
std
::
endl
;
}
middleman
::
module
::
id_t
middleman
::
id
()
const
{
...
...
@@ -93,6 +97,14 @@ void* middleman::subtype_ptr() {
return
this
;
}
expected
<
endpoint_manager_ptr
>
middleman
::
connect
(
const
uri
&
locator
)
{
auto
ptr
=
backend
(
locator
.
scheme
());
if
(
auto
ret
=
ptr
->
connect
(
locator
))
return
ret
;
else
return
sec
::
cannot_connect_to_node
;
}
void
middleman
::
resolve
(
const
uri
&
locator
,
const
actor
&
listener
)
{
auto
ptr
=
backend
(
locator
.
scheme
());
if
(
ptr
!=
nullptr
)
...
...
@@ -111,4 +123,12 @@ middleman_backend* middleman::backend(string_view scheme) const noexcept {
return
nullptr
;
}
expected
<
uint16_t
>
middleman
::
port
(
string_view
scheme
)
const
{
auto
ptr
=
backend
(
scheme
);
if
(
ptr
!=
nullptr
)
return
ptr
->
port
();
else
return
sec
::
invalid_protocol_family
;
}
}
// namespace caf::net
libcaf_net/test/net/backend/tcp.cpp
0 → 100644
View file @
3cd6dd58
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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. *
******************************************************************************/
#define CAF_SUITE net.backend.tcp
#include "caf/net/backend/tcp.hpp"
#include "caf/net/test/host_fixture.hpp"
#include "caf/test/dsl.hpp"
#include "caf/ip_endpoint.hpp"
#include "caf/net/middleman.hpp"
#include "caf/net/socket_guard.hpp"
using
namespace
caf
;
using
namespace
caf
::
net
;
namespace
{
struct
config
:
actor_system_config
{
config
()
{
put
(
content
,
"middleman.this-node"
,
unbox
(
make_uri
(
"tcp://earth"
)));
load
<
middleman
,
backend
::
tcp
>
();
}
};
struct
fixture
:
test_coordinator_fixture
<
config
>
,
host_fixture
{
using
byte_buffer_ptr
=
std
::
shared_ptr
<
byte_buffer
>
;
fixture
()
:
mm
{
sys
.
network_manager
()},
mpx
{
mm
.
mpx
()}
{
mpx
->
set_thread_id
();
handle_io_events
();
}
bool
handle_io_event
()
override
{
return
mpx
->
poll_once
(
false
);
}
net
::
middleman
&
mm
;
const
multiplexer_ptr
&
mpx
;
};
}
// namespace
CAF_TEST_FIXTURE_SCOPE
(
tcp_backend_tests
,
fixture
)
CAF_TEST
(
doorman
accept
)
{
CAF_CHECK_EQUAL
(
mpx
->
num_socket_managers
(),
2
);
auto
backend
=
mm
.
backend
(
"tcp"
);
CAF_CHECK
(
backend
);
auto
port
=
backend
->
port
();
CAF_MESSAGE
(
"trying to connect to system with "
<<
CAF_ARG
(
port
));
ip_endpoint
ep
;
auto
ep_str
=
std
::
string
(
"[::1]:"
)
+
std
::
to_string
(
port
);
if
(
auto
err
=
detail
::
parse
(
ep_str
,
ep
))
CAF_FAIL
(
"could not parse "
<<
CAF_ARG
(
ep_str
)
<<
" "
<<
CAF_ARG
(
err
));
auto
sock
=
make_connected_tcp_stream_socket
(
ep
);
if
(
!
sock
)
CAF_FAIL
(
"could not connect"
);
auto
guard
=
make_socket_guard
(
*
sock
);
handle_io_event
();
CAF_CHECK_EQUAL
(
mpx
->
num_socket_managers
(),
3
);
}
CAF_TEST
(
connect
)
{
ip_endpoint
ep
;
if
(
auto
err
=
detail
::
parse
(
"[::]:0"
,
ep
))
CAF_FAIL
(
"could not parse endpoint"
<<
err
);
auto
acceptor
=
make_tcp_accept_socket
(
ep
);
CAF_CHECK
(
!
acceptor
)
auto
acc_guard
=
make_socket_guard
(
*
acceptor
);
auto
port
=
local_port
(
*
acc_guard
);
auto
uri_str
=
std
::
string
(
"tcp://localhost:"
)
+
std
::
to_string
(
port
);
CAF_MESSAGE
(
"connecting to "
<<
CAF_ARG
(
uri_str
));
auto
ptr
=
mm
.
backend
(
"tcp"
);
CAF_CHECK
(
mm
->
connect
(
make_uri
(
ep_string
)));
}
CAF_TEST_FIXTURE_SCOPE_END
()
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