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
c5e3b77b
Commit
c5e3b77b
authored
Aug 21, 2019
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ipv6_endpoint
parent
80bb0a1e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
245 additions
and
0 deletions
+245
-0
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+1
-0
libcaf_core/caf/ip_endpoint.hpp
libcaf_core/caf/ip_endpoint.hpp
+28
-0
libcaf_core/caf/ipv6_endpoint.hpp
libcaf_core/caf/ipv6_endpoint.hpp
+89
-0
libcaf_core/src/ipv6_endpoint.cpp
libcaf_core/src/ipv6_endpoint.cpp
+84
-0
libcaf_core/test/ipv6_endpoint.cpp
libcaf_core/test/ipv6_endpoint.cpp
+43
-0
No files found.
libcaf_core/CMakeLists.txt
View file @
c5e3b77b
...
...
@@ -68,6 +68,7 @@ set(LIBCAF_CORE_SRCS
src/ipv4_endpoint.cpp
src/ipv4_subnet.cpp
src/ipv6_address.cpp
src/ipv6_endpoint.cpp
src/ipv6_subnet.cpp
src/local_actor.cpp
src/logger.cpp
...
...
libcaf_core/caf/ip_endpoint.hpp
0 → 100644
View file @
c5e3b77b
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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 "caf/ipv6_endpoint.hpp"
namespace
caf
{
/// An IP endpoint that contains an ipv6_address and a port.
using
ip_endpoint
=
ipv6_endpoint
;
}
// namespace caf
libcaf_core/caf/ipv6_endpoint.hpp
0 → 100644
View file @
c5e3b77b
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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 <deque>
#include <functional>
#include <string>
#include <vector>
#include "caf/ipv6_address.hpp"
#include "caf/meta/type_name.hpp"
namespace
caf
{
/// A hashable endpoint abstraction for ipv6.
struct
ipv6_endpoint
:
detail
::
comparable
<
ipv6_endpoint
>
{
public:
// -- constructors -----------------------------------------------------------
ipv6_endpoint
(
ipv6_address
address
,
uint16_t
port
);
ipv6_endpoint
()
=
default
;
ipv6_endpoint
(
const
ipv6_endpoint
&
)
=
default
;
ipv6_endpoint
&
operator
=
(
const
ipv6_endpoint
&
)
=
default
;
// -- properties -------------------------------------------------------------
/// Returns the IPv6 address.
ipv6_address
address
()
const
noexcept
;
/// Sets the address of this endpoint.
void
address
(
ipv6_address
x
)
noexcept
;
/// Returns the port of this endpoint.
uint16_t
port
()
const
noexcept
;
/// Sets the port of this endpoint.
void
port
(
uint16_t
x
)
noexcept
;
/// Returns a hash for this object.
size_t
hash_code
()
const
noexcept
;
/// compares This endpoint to another.
/// Returns 0 if equal, otherwise >0 if this > x and <0 if this < x.
long
compare
(
ipv6_endpoint
x
)
const
noexcept
;
template
<
class
Inspector
>
friend
typename
Inspector
::
result_type
inspect
(
Inspector
&
f
,
ipv6_endpoint
&
x
)
{
return
f
(
meta
::
type_name
(
"ipv6_endpoint"
),
x
.
address_
,
x
.
port_
);
}
private:
ipv6_address
address_
;
/// The address of this endpoint.
uint16_t
port_
;
/// The port of this endpoint.
};
std
::
string
to_string
(
const
ipv6_endpoint
&
ep
);
}
// namespace caf
namespace
std
{
template
<
>
struct
hash
<
caf
::
ipv6_endpoint
>
{
size_t
operator
()(
const
caf
::
ipv6_endpoint
&
ep
)
const
noexcept
{
return
ep
.
hash_code
();
}
};
}
// namespace std
libcaf_core/src/ipv6_endpoint.cpp
0 → 100644
View file @
c5e3b77b
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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/ipv6_endpoint.hpp"
#include "caf/detail/fnv_hash.hpp"
#ifdef CAF_WINDOWS
# include <windows.h>
# include <winsock2.h>
# include <ws2ipdef.h>
# include <ws2tcpip.h>
#else
# include <arpa/inet.h>
# include <cerrno>
# include <netinet/in.h>
# include <netinet/ip.h>
# include <sys/socket.h>
# include <unistd.h>
#endif
#ifdef CAF_WINDOWS
using
sa_family_t
=
short
;
#endif
using
caf
::
detail
::
fnv_hash
;
using
caf
::
detail
::
fnv_hash_append
;
namespace
caf
{
ipv6_endpoint
::
ipv6_endpoint
(
ipv6_address
address
,
uint16_t
port
)
:
address_
(
address
),
port_
(
port
)
{
// nop
}
ipv6_address
ipv6_endpoint
::
address
()
const
noexcept
{
return
address_
;
}
void
ipv6_endpoint
::
address
(
ipv6_address
x
)
noexcept
{
address_
=
x
;
}
uint16_t
ipv6_endpoint
::
port
()
const
noexcept
{
return
port_
;
}
void
ipv6_endpoint
::
port
(
uint16_t
x
)
noexcept
{
port_
=
x
;
}
size_t
ipv6_endpoint
::
hash_code
()
const
noexcept
{
auto
result
=
fnv_hash
(
address_
.
data
());
return
fnv_hash_append
(
result
,
port_
);
}
long
ipv6_endpoint
::
compare
(
ipv6_endpoint
x
)
const
noexcept
{
auto
res
=
address_
.
compare
(
x
.
address
());
if
(
res
!=
0
)
return
port_
-
x
.
port
();
else
return
res
;
}
std
::
string
to_string
(
const
ipv6_endpoint
&
ep
)
{
return
to_string
(
ep
.
address
())
+
":"
+
std
::
to_string
(
ep
.
port
());
}
}
// namespace caf
libcaf_core/test/ipv6_endpoint.cpp
0 → 100644
View file @
c5e3b77b
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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 ipv6_endpoint
#include "caf/ipv6_endpoint.hpp"
#include "caf/test/unit_test.hpp"
#include "caf/ipv6_address.hpp"
using
namespace
caf
;
CAF_TEST
(
constructing
and
equality
)
{
const
uint16_t
port
=
8888
;
ipv6_address
::
array_type
localhost_bytes
{
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
}};
ipv6_address
addr
(
localhost_bytes
);
ipv6_endpoint
ep1
(
addr
,
port
);
CAF_CHECK_EQUAL
(
ep1
.
address
(),
addr
);
CAF_CHECK_EQUAL
(
ep1
.
port
(),
port
);
ipv6_endpoint
ep2
;
ep2
.
address
(
addr
);
ep2
.
port
(
port
);
CAF_CHECK_EQUAL
(
ep2
.
address
(),
addr
);
CAF_CHECK_EQUAL
(
ep2
.
port
(),
port
);
CAF_CHECK_EQUAL
(
ep1
,
ep2
);
}
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