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
bf7fb0ba
Commit
bf7fb0ba
authored
Sep 17, 2019
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up allocation and error handling
parent
74de7157
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
8 deletions
+7
-8
libcaf_net/src/ip.cpp
libcaf_net/src/ip.cpp
+7
-8
No files found.
libcaf_net/src/ip.cpp
View file @
bf7fb0ba
...
@@ -150,20 +150,19 @@ std::string hostname() {
...
@@ -150,20 +150,19 @@ std::string hostname() {
std
::
vector
<
ip_address
>
local_addresses
(
string_view
host
)
{
std
::
vector
<
ip_address
>
local_addresses
(
string_view
host
)
{
using
adapters_ptr
=
std
::
unique_ptr
<
IP_ADAPTER_ADDRESSES
,
void
(
*
)(
void
*
)
>
;
using
adapters_ptr
=
std
::
unique_ptr
<
IP_ADAPTER_ADDRESSES
,
void
(
*
)(
void
*
)
>
;
using
wbuf_ptr
=
std
::
unique_ptr
<
IP_ADAPTER_ADDRESSES
,
void
(
*
)(
void
*
)
>
;
if
(
host
==
v4_any_addr
)
if
(
host
==
v4_any_addr
)
return
{
ip_address
{
make_ipv4_address
(
0
,
0
,
0
,
0
)}};
return
{
ip_address
{
make_ipv4_address
(
0
,
0
,
0
,
0
)}};
if
(
host
==
v6_any_addr
)
if
(
host
==
v6_any_addr
)
return
{
ip_address
{}};
return
{
ip_address
{}};
ULONG
len
=
0
;
ULONG
len
=
0
;
auto
err
=
GetAdaptersAddresses
(
AF_UNSPEC
,
GAA_FLAG_INCLUDE_PREFIX
,
nullptr
,
if
(
GetAdaptersAddresses
(
AF_UNSPEC
,
GAA_FLAG_INCLUDE_PREFIX
,
nullptr
,
nullptr
,
nullptr
,
&
len
);
&
len
)
if
(
err
!=
ERROR_BUFFER_OVERFLOW
)
{
!=
ERROR_BUFFER_OVERFLOW
)
{
CAF_LOG_ERROR
(
"failed to get adapter addresses buffer length"
);
CAF_LOG_ERROR
(
"failed to get adapter addresses buffer length"
);
return
{};
return
{};
}
}
auto
adapters
=
adapters_ptr
{
reinterpret_cast
<
IP_ADAPTER_ADDRESSES
*>
(
auto
adapters
=
adapters_ptr
{
reinterpret_cast
<
IP_ADAPTER_ADDRESSES
*>
(
::
new
uint8_t
[
len
]
),
::
malloc
(
len
),
free
};
free
};
if
(
!
adapters
)
{
if
(
!
adapters
)
{
CAF_LOG_ERROR
(
"malloc failed"
);
CAF_LOG_ERROR
(
"malloc failed"
);
...
@@ -172,9 +171,9 @@ std::vector<ip_address> local_addresses(string_view host) {
...
@@ -172,9 +171,9 @@ std::vector<ip_address> local_addresses(string_view host) {
// TODO: The Microsoft WIN32 API example propopses to try three times, other
// TODO: The Microsoft WIN32 API example propopses to try three times, other
// examples online just perform the call once. If we notice the call to be
// examples online just perform the call once. If we notice the call to be
// unreliable, we might adapt that behavior.
// unreliable, we might adapt that behavior.
err
=
GetAdaptersAddresses
(
AF_UNSPEC
,
GAA_FLAG_INCLUDE_PREFIX
,
nullptr
,
if
(
GetAdaptersAddresses
(
AF_UNSPEC
,
GAA_FLAG_INCLUDE_PREFIX
,
nullptr
,
adapters
.
get
(),
&
len
);
adapters
.
get
(),
&
len
)
if
(
err
!=
ERROR_SUCCESS
)
{
!=
ERROR_SUCCESS
)
{
CAF_LOG_ERROR
(
"failed to get adapter addresses"
);
CAF_LOG_ERROR
(
"failed to get adapter addresses"
);
return
{};
return
{};
}
}
...
...
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