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
9a376fbe
Commit
9a376fbe
authored
Feb 01, 2019
by
Simon Giesecke
Committed by
Simon Giesecke
Feb 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: code duplication in get_address of ipc/tcp/tipc listener classes
Solution: pull up to base class
parent
5c81bbe8
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
43 additions
and
43 deletions
+43
-43
ipc_listener.cpp
src/ipc_listener.cpp
+2
-10
ipc_listener.hpp
src/ipc_listener.hpp
+2
-2
stream_listener_base.cpp
src/stream_listener_base.cpp
+9
-2
stream_listener_base.hpp
src/stream_listener_base.hpp
+19
-1
tcp_listener.cpp
src/tcp_listener.cpp
+2
-11
tcp_listener.hpp
src/tcp_listener.hpp
+2
-2
tipc_address.cpp
src/tipc_address.cpp
+1
-1
tipc_address.hpp
src/tipc_address.hpp
+1
-1
tipc_listener.cpp
src/tipc_listener.cpp
+3
-11
tipc_listener.hpp
src/tipc_listener.hpp
+2
-2
No files found.
src/ipc_listener.cpp
View file @
9a376fbe
...
...
@@ -150,17 +150,9 @@ void zmq::ipc_listener_t::in_event ()
create_engine
(
fd
);
}
int
zmq
::
ipc_listener_t
::
get_address
(
std
::
string
&
addr_
)
std
::
string
zmq
::
ipc_listener_t
::
get_socket_name
(
zmq
::
fd_t
fd_
)
const
{
struct
sockaddr_storage
ss
;
const
zmq_socklen_t
sl
=
get_socket_address
(
&
ss
);
if
(
sl
==
0
)
{
addr_
.
clear
();
return
-
1
;
}
ipc_address_t
addr
(
reinterpret_cast
<
struct
sockaddr
*>
(
&
ss
),
sl
);
return
addr
.
to_string
(
addr_
);
return
stream_listener_base_t
::
get_socket_name
<
ipc_address_t
>
(
fd_
);
}
int
zmq
::
ipc_listener_t
::
set_address
(
const
char
*
addr_
)
...
...
src/ipc_listener.hpp
View file @
9a376fbe
...
...
@@ -50,8 +50,8 @@ class ipc_listener_t : public stream_listener_base_t
// Set address to listen on.
int
set_address
(
const
char
*
addr_
);
// Get the bound address for use with wildcards
int
get_address
(
std
::
string
&
addr_
)
;
protected
:
std
::
string
get_socket_name
(
fd_t
fd_
)
const
;
private
:
// Handlers for I/O events.
...
...
src/stream_listener_base.cpp
View file @
9a376fbe
...
...
@@ -51,13 +51,20 @@ zmq::stream_listener_base_t::~stream_listener_base_t ()
zmq_assert
(
!
_handle
);
}
int
zmq
::
stream_listener_base_t
::
get_address
(
std
::
string
&
addr_
)
const
{
addr_
=
get_socket_name
(
_s
);
return
addr_
.
empty
()
?
-
1
:
0
;
}
zmq
::
zmq_socklen_t
zmq
::
stream_listener_base_t
::
get_socket_address
(
sockaddr_storage
*
ss_
)
const
zmq
::
stream_listener_base_t
::
get_socket_address
(
fd_t
fd_
,
sockaddr_storage
*
ss_
)
{
zmq_socklen_t
sl
=
static_cast
<
zmq_socklen_t
>
(
sizeof
(
*
ss_
));
const
int
rc
=
getsockname
(
_s
,
reinterpret_cast
<
struct
sockaddr
*>
(
ss_
),
&
sl
);
getsockname
(
fd_
,
reinterpret_cast
<
struct
sockaddr
*>
(
ss_
),
&
sl
);
return
rc
!=
0
?
0
:
sl
;
}
...
...
src/stream_listener_base.hpp
View file @
9a376fbe
...
...
@@ -57,8 +57,26 @@ class stream_listener_base_t : public own_t, public io_object_t
const
options_t
&
options_
);
~
stream_listener_base_t
();
// Get the bound address for use with wildcards
int
get_address
(
std
::
string
&
addr_
)
const
;
protected
:
zmq_socklen_t
get_socket_address
(
sockaddr_storage
*
ss_
)
const
;
static
zmq_socklen_t
get_socket_address
(
fd_t
fd_
,
sockaddr_storage
*
ss_
);
virtual
std
::
string
get_socket_name
(
fd_t
fd_
)
const
=
0
;
template
<
typename
T
>
static
std
::
string
get_socket_name
(
fd_t
fd_
)
{
struct
sockaddr_storage
ss
;
const
zmq_socklen_t
sl
=
get_socket_address
(
fd_
,
&
ss
);
if
(
sl
==
0
)
{
return
std
::
string
();
}
const
T
addr
(
reinterpret_cast
<
struct
sockaddr
*>
(
&
ss
),
sl
);
std
::
string
address_string
;
addr
.
to_string
(
address_string
);
return
address_string
;
}
private
:
// Handlers for incoming commands.
...
...
src/tcp_listener.cpp
View file @
9a376fbe
...
...
@@ -91,18 +91,9 @@ void zmq::tcp_listener_t::in_event ()
create_engine
(
fd
);
}
int
zmq
::
tcp_listener_t
::
get_address
(
std
::
string
&
addr_
)
std
::
string
zmq
::
tcp_listener_t
::
get_socket_name
(
zmq
::
fd_t
fd_
)
const
{
// Get the details of the TCP socket
struct
sockaddr_storage
ss
;
const
zmq_socklen_t
sl
=
get_socket_address
(
&
ss
);
if
(
!
sl
)
{
addr_
.
clear
();
return
-
1
;
}
tcp_address_t
addr
(
reinterpret_cast
<
struct
sockaddr
*>
(
&
ss
),
sl
);
return
addr
.
to_string
(
addr_
);
return
stream_listener_base_t
::
get_socket_name
<
tcp_address_t
>
(
fd_
);
}
int
zmq
::
tcp_listener_t
::
set_address
(
const
char
*
addr_
)
...
...
src/tcp_listener.hpp
View file @
9a376fbe
...
...
@@ -46,8 +46,8 @@ class tcp_listener_t : public stream_listener_base_t
// Set address to listen on.
int
set_address
(
const
char
*
addr_
);
// Get the bound address for use with wildcard
int
get_address
(
std
::
string
&
addr_
)
;
protected
:
std
::
string
get_socket_name
(
fd_t
fd_
)
const
;
private
:
// Handlers for I/O events.
...
...
src/tipc_address.cpp
View file @
9a376fbe
...
...
@@ -130,7 +130,7 @@ int zmq::tipc_address_t::resolve (const char *name)
return
EINVAL
;
}
int
zmq
::
tipc_address_t
::
to_string
(
std
::
string
&
addr_
)
int
zmq
::
tipc_address_t
::
to_string
(
std
::
string
&
addr_
)
const
{
if
(
address
.
family
!=
AF_TIPC
)
{
addr_
.
clear
();
...
...
src/tipc_address.hpp
View file @
9a376fbe
...
...
@@ -55,7 +55,7 @@ class tipc_address_t
int
resolve
(
const
char
*
name
);
// The opposite to resolve()
int
to_string
(
std
::
string
&
addr_
);
int
to_string
(
std
::
string
&
addr_
)
const
;
// Handling different TIPC address types
bool
is_service
()
const
;
...
...
src/tipc_listener.cpp
View file @
9a376fbe
...
...
@@ -76,17 +76,9 @@ void zmq::tipc_listener_t::in_event ()
create_engine
(
fd
);
}
int
zmq
::
tipc_listener_t
::
get_address
(
std
::
string
&
addr_
)
std
::
string
zmq
::
tipc_listener_t
::
get_socket_name
(
zmq
::
fd_t
fd_
)
const
{
struct
sockaddr_storage
ss
;
const
zmq_socklen_t
sl
=
get_socket_address
(
&
ss
);
if
(
!
sl
)
{
addr_
.
clear
();
return
-
1
;
}
tipc_address_t
addr
((
struct
sockaddr
*
)
&
ss
,
sl
);
return
addr
.
to_string
(
addr_
);
return
stream_listener_base_t
::
get_socket_name
<
tipc_address_t
>
(
fd_
);
}
int
zmq
::
tipc_listener_t
::
set_address
(
const
char
*
addr_
)
...
...
@@ -111,7 +103,7 @@ int zmq::tipc_listener_t::set_address (const char *addr_)
// If random Port Identity, update address object to reflect the assigned address
if
(
_address
.
is_random
())
{
struct
sockaddr_storage
ss
;
const
zmq_socklen_t
sl
=
get_socket_address
(
&
ss
);
const
zmq_socklen_t
sl
=
get_socket_address
(
_s
,
&
ss
);
if
(
sl
==
0
)
goto
error
;
...
...
src/tipc_listener.hpp
View file @
9a376fbe
...
...
@@ -52,8 +52,8 @@ class tipc_listener_t : public stream_listener_base_t
// Set address to listen on.
int
set_address
(
const
char
*
addr_
);
// Get the bound address for use with wildcards
int
get_address
(
std
::
string
&
addr_
)
;
protected
:
std
::
string
get_socket_name
(
fd_t
fd_
)
const
;
private
:
// Handlers for I/O events.
...
...
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