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
80bb0a1e
Commit
80bb0a1e
authored
Aug 21, 2019
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ipv4_endpoint
parent
bc496094
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
210 additions
and
0 deletions
+210
-0
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+1
-0
libcaf_core/caf/ipv4_endpoint.hpp
libcaf_core/caf/ipv4_endpoint.hpp
+84
-0
libcaf_core/src/ipv4_endpoint.cpp
libcaf_core/src/ipv4_endpoint.cpp
+84
-0
libcaf_core/test/ipv4_endpoint.cpp
libcaf_core/test/ipv4_endpoint.cpp
+41
-0
No files found.
libcaf_core/CMakeLists.txt
View file @
80bb0a1e
...
@@ -65,6 +65,7 @@ set(LIBCAF_CORE_SRCS
...
@@ -65,6 +65,7 @@ set(LIBCAF_CORE_SRCS
src/ini_consumer.cpp
src/ini_consumer.cpp
src/invoke_result_visitor.cpp
src/invoke_result_visitor.cpp
src/ipv4_address.cpp
src/ipv4_address.cpp
src/ipv4_endpoint.cpp
src/ipv4_subnet.cpp
src/ipv4_subnet.cpp
src/ipv6_address.cpp
src/ipv6_address.cpp
src/ipv6_subnet.cpp
src/ipv6_subnet.cpp
...
...
libcaf_core/caf/ipv4_endpoint.hpp
0 → 100644
View file @
80bb0a1e
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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/ipv4_address.hpp"
#include "caf/meta/type_name.hpp"
namespace
caf
{
/// A hashable endpoint abstraction for ipv4
struct
ipv4_endpoint
:
detail
::
comparable
<
ipv4_endpoint
>
{
public:
// -- constructors -----------------------------------------------------------
ipv4_endpoint
(
ipv4_address
address
,
uint16_t
port
);
ipv4_endpoint
()
=
default
;
ipv4_endpoint
(
const
ipv4_endpoint
&
)
=
default
;
ipv4_endpoint
&
operator
=
(
const
ipv4_endpoint
&
)
=
default
;
// -- properties -------------------------------------------------------------
/// Returns the IPv6 address.
ipv4_address
address
()
const
noexcept
;
/// Sets the address of this endpoint.
void
address
(
ipv4_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
(
ipv4_endpoint
x
)
const
noexcept
;
template
<
class
Inspector
>
friend
typename
Inspector
::
result_type
inspect
(
Inspector
&
f
,
ipv4_endpoint
&
x
)
{
return
f
(
meta
::
type_name
(
"ipv4_endpoint"
),
x
.
address_
,
x
.
port_
);
}
private:
ipv4_address
address_
;
/// The address of this endpoint.
uint16_t
port_
;
/// The port of this endpoint.
};
std
::
string
to_string
(
const
ipv4_endpoint
&
ep
);
}
// namespace caf
namespace
std
{
template
<
>
struct
hash
<
caf
::
ipv4_endpoint
>
{
size_t
operator
()(
const
caf
::
ipv4_endpoint
&
ep
)
const
noexcept
{
return
ep
.
hash_code
();
}
};
}
// namespace std
libcaf_core/src/ipv4_endpoint.cpp
0 → 100644
View file @
80bb0a1e
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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/ipv4_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
{
ipv4_endpoint
::
ipv4_endpoint
(
ipv4_address
address
,
uint16_t
port
)
:
address_
(
address
),
port_
(
port
)
{
// nop
}
ipv4_address
ipv4_endpoint
::
address
()
const
noexcept
{
return
address_
;
}
void
ipv4_endpoint
::
address
(
ipv4_address
x
)
noexcept
{
address_
=
x
;
}
uint16_t
ipv4_endpoint
::
port
()
const
noexcept
{
return
port_
;
}
void
ipv4_endpoint
::
port
(
uint16_t
x
)
noexcept
{
port_
=
x
;
}
size_t
ipv4_endpoint
::
hash_code
()
const
noexcept
{
auto
result
=
fnv_hash
(
address_
.
data
());
return
fnv_hash_append
(
result
,
port_
);
}
long
ipv4_endpoint
::
compare
(
ipv4_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
ipv4_endpoint
&
ep
)
{
return
to_string
(
ep
.
address
())
+
":"
+
std
::
to_string
(
ep
.
port
());
}
}
// namespace caf
libcaf_core/test/ipv4_endpoint.cpp
0 → 100644
View file @
80bb0a1e
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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 ipv4_endpoint
#include "caf/ipv4_endpoint.hpp"
#include "caf/test/unit_test.hpp"
#include "caf/ipv4_address.hpp"
using
namespace
caf
;
CAF_TEST
(
constructing
and
equality
)
{
const
uint16_t
port
=
8888
;
auto
addr
=
make_ipv4_address
(
127
,
0
,
0
,
1
);
ipv4_endpoint
ep1
(
addr
,
port
);
CAF_CHECK_EQUAL
(
ep1
.
address
(),
addr
);
CAF_CHECK_EQUAL
(
ep1
.
port
(),
port
);
ipv4_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