Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
cdc6c66f
Commit
cdc6c66f
authored
Aug 15, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: complexity of term_endpoint
Solution: extract resolve_tcp_addr function
parent
a2d736c1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
29 deletions
+37
-29
socket_base.cpp
src/socket_base.cpp
+34
-29
socket_base.hpp
src/socket_base.hpp
+3
-0
No files found.
src/socket_base.cpp
View file @
cdc6c66f
...
...
@@ -968,6 +968,33 @@ int zmq::socket_base_t::connect (const char *addr_)
return
0
;
}
std
::
string
zmq
::
socket_base_t
::
resolve_tcp_addr
(
std
::
string
endpoint_address_
,
const
char
*
tcp_address_
)
{
// The resolved last_endpoint is used as a key in the endpoints map.
// The address passed by the user might not match in the TCP case due to
// IPv4-in-IPv6 mapping (EG: tcp://[::ffff:127.0.0.1]:9999), so try to
// resolve before giving up. Given at this stage we don't know whether a
// socket is connected or bound, try with both.
if
(
_endpoints
.
find
(
endpoint_address_
)
==
_endpoints
.
end
())
{
tcp_address_t
*
tcp_addr
=
new
(
std
::
nothrow
)
tcp_address_t
();
alloc_assert
(
tcp_addr
);
int
rc
=
tcp_addr
->
resolve
(
tcp_address_
,
false
,
options
.
ipv6
);
if
(
rc
==
0
)
{
tcp_addr
->
to_string
(
endpoint_address_
);
if
(
_endpoints
.
find
(
endpoint_address_
)
==
_endpoints
.
end
())
{
rc
=
tcp_addr
->
resolve
(
tcp_address_
,
true
,
options
.
ipv6
);
if
(
rc
==
0
)
{
tcp_addr
->
to_string
(
endpoint_address_
);
}
}
}
LIBZMQ_DELETE
(
tcp_addr
);
}
return
endpoint_address_
;
}
void
zmq
::
socket_base_t
::
add_endpoint
(
const
char
*
addr_
,
own_t
*
endpoint_
,
pipe_t
*
pipe_
)
...
...
@@ -996,7 +1023,7 @@ int zmq::socket_base_t::term_endpoint (const char *addr_)
// Process pending commands, if any, since there could be pending unprocessed process_own()'s
// (from launch_child() for example) we're asked to terminate now.
int
rc
=
process_commands
(
0
,
false
);
const
int
rc
=
process_commands
(
0
,
false
);
if
(
unlikely
(
rc
!=
0
))
{
return
-
1
;
}
...
...
@@ -1008,41 +1035,19 @@ int zmq::socket_base_t::term_endpoint (const char *addr_)
return
-
1
;
}
const
std
::
string
addr_str
=
std
::
string
(
addr_
);
// Disconnect an inproc socket
if
(
protocol
==
"inproc"
)
{
const
std
::
string
addr_str
=
std
::
string
(
addr_
);
return
unregister_endpoint
(
addr_str
,
this
)
==
0
?
0
:
_inprocs
.
erase_pipes
(
addr_str
);
}
std
::
string
resolved_addr
=
addr_
;
// The resolved last_endpoint is used as a key in the endpoints map.
// The address passed by the user might not match in the TCP case due to
// IPv4-in-IPv6 mapping (EG: tcp://[::ffff:127.0.0.1]:9999), so try to
// resolve before giving up. Given at this stage we don't know whether a
// socket is connected or bound, try with both.
if
(
protocol
==
protocol_name
::
tcp
)
{
if
(
_endpoints
.
find
(
resolved_addr
)
==
_endpoints
.
end
())
{
tcp_address_t
*
tcp_addr
=
new
(
std
::
nothrow
)
tcp_address_t
();
alloc_assert
(
tcp_addr
);
rc
=
tcp_addr
->
resolve
(
address
.
c_str
(),
false
,
options
.
ipv6
);
if
(
rc
==
0
)
{
tcp_addr
->
to_string
(
resolved_addr
);
if
(
_endpoints
.
find
(
resolved_addr
)
==
_endpoints
.
end
())
{
rc
=
tcp_addr
->
resolve
(
address
.
c_str
(),
true
,
options
.
ipv6
);
if
(
rc
==
0
)
{
tcp_addr
->
to_string
(
resolved_addr
);
}
}
}
LIBZMQ_DELETE
(
tcp_addr
);
}
}
const
std
::
string
resolved_addr
=
protocol
==
protocol_name
::
tcp
?
resolve_tcp_addr
(
addr_str
,
address
.
c_str
())
:
addr_str
;
// Find the endpoints range (if any) corresponding to the addr_ string.
const
std
::
pair
<
endpoints_t
::
iterator
,
endpoints_t
::
iterator
>
range
=
...
...
src/socket_base.hpp
View file @
cdc6c66f
...
...
@@ -259,6 +259,9 @@ class socket_base_t : public own_t,
void
update_pipe_options
(
int
option_
);
std
::
string
resolve_tcp_addr
(
std
::
string
endpoint_address_
,
const
char
*
tcp_address_
);
// Socket's mailbox object.
i_mailbox
*
_mailbox
;
...
...
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