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
770f8433
Commit
770f8433
authored
Feb 11, 2012
by
Ian Barber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allowing value 0, and moving code to get_address functions based on feedback
parent
91bf4944
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
44 deletions
+41
-44
AUTHORS
AUTHORS
+1
-0
ipc_listener.cpp
src/ipc_listener.cpp
+12
-9
ipc_listener.hpp
src/ipc_listener.hpp
+0
-4
tcp_address.cpp
src/tcp_address.cpp
+2
-1
tcp_listener.cpp
src/tcp_listener.cpp
+25
-25
tcp_listener.hpp
src/tcp_listener.hpp
+1
-5
No files found.
AUTHORS
View file @
770f8433
...
...
@@ -33,6 +33,7 @@ Gerard Toonstra <gtoonstra@gmail.com>
Ghislain Putois <ghpu@infonie.fr>
Gonzalo Diethelm <gdiethelm@dcv.cl>
Guido Goldstein <zmq@a-nugget.de>
Ian Barber <ian.barber@gmail.com>
Ilja Golshtein <ilejncs@narod.ru>
Ivo Danihelka <ivo@danihelka.net>
Jacob Rideout <jacob.rideout@returnpath.net>
...
...
src/ipc_listener.cpp
View file @
770f8433
...
...
@@ -97,12 +97,18 @@ void zmq::ipc_listener_t::in_event ()
int
zmq
::
ipc_listener_t
::
get_address
(
unsigned
char
*
addr
,
size_t
*
len
)
{
if
(
bound_addr_len
==
0
)
{
return
-
1
;
struct
sockaddr_un
sun
;
int
rc
;
// Get the details of the IPC socket
socklen_t
sl
=
sizeof
(
sockaddr_un
);
rc
=
getsockname
(
s
,
(
sockaddr
*
)
&
sun
,
&
sl
);
if
(
rc
!=
0
)
{
return
rc
;
}
memcpy
(
addr
,
bound_addr
,
bound_addr_len
+
1
);
*
len
=
bound_addr_len
+
1
;
// Store the address for retrieval by users using wildcards
*
len
=
sprintf
((
char
*
)
addr
,
"ipc://%s"
,
sun
.
sun_path
);
return
0
;
}
...
...
@@ -141,10 +147,7 @@ int zmq::ipc_listener_t::set_address (const char *addr_)
rc
=
listen
(
s
,
options
.
backlog
);
if
(
rc
!=
0
)
return
-
1
;
// Return the bound address
bound_addr_len
=
sprintf
(
bound_addr
,
"ipc://%s"
,
addr_
);
return
0
;
}
...
...
src/ipc_listener.hpp
View file @
770f8433
...
...
@@ -68,10 +68,6 @@ namespace zmq
// newly created connection. The function may return retired_fd
// if the connection was dropped while waiting in the listen backlog.
fd_t
accept
();
// Store the connected endpoint for binds to port 0
char
bound_addr
[
256
];
size_t
bound_addr_len
;
// True, if the undelying file for UNIX domain socket exists.
bool
has_file
;
...
...
src/tcp_address.cpp
View file @
770f8433
...
...
@@ -388,7 +388,8 @@ int zmq::tcp_address_t::resolve (const char *name_, bool local_, bool ipv4only_)
addr_str
=
addr_str
.
substr
(
1
,
addr_str
.
size
()
-
2
);
uint16_t
port
;
if
(
port_str
[
0
]
==
'*'
)
{
// Allow 0 specifically, to detect invalid port error in atoi if not
if
(
port_str
[
0
]
==
'*'
||
port_str
[
0
]
==
'0'
)
{
// Resolve wildcard to 0 to allow autoselection of port
port
=
0
;
}
else
{
...
...
src/tcp_listener.cpp
View file @
770f8433
...
...
@@ -52,7 +52,6 @@ zmq::tcp_listener_t::tcp_listener_t (io_thread_t *io_thread_,
socket_base_t
*
socket_
,
const
options_t
&
options_
)
:
own_t
(
io_thread_
,
options_
),
io_object_t
(
io_thread_
),
bound_addr_len
(
0
),
has_file
(
false
),
s
(
retired_fd
),
socket
(
socket_
)
...
...
@@ -121,13 +120,33 @@ void zmq::tcp_listener_t::close ()
}
int
zmq
::
tcp_listener_t
::
get_address
(
unsigned
char
*
addr
,
size_t
*
len
)
{
if
(
bound_addr_len
==
0
)
{
return
-
1
;
{
struct
sockaddr
sa
;
char
host
[
INET6_ADDRSTRLEN
];
int
port
,
rc
;
// Get the details of the TCP socket
socklen_t
sl
=
sizeof
(
sockaddr
);
rc
=
getsockname
(
s
,
&
sa
,
&
sl
);
if
(
rc
!=
0
)
{
return
rc
;
}
// Split the retrieval between IPv4 and v6 addresses
if
(
sa
.
sa_family
==
AF_INET
)
{
inet_ntop
(
AF_INET
,
&
(((
struct
sockaddr_in
*
)
&
sa
)
->
sin_addr
),
host
,
INET6_ADDRSTRLEN
);
port
=
ntohs
(
((
struct
sockaddr_in
*
)
&
sa
)
->
sin_port
);
// Store the address for retrieval by users using wildcards
*
len
=
sprintf
((
char
*
)
addr
,
"tcp://%s:%d"
,
host
,
port
);
}
else
{
inet_ntop
(
AF_INET6
,
&
(((
struct
sockaddr_in6
*
)
&
sa
)
->
sin6_addr
),
host
,
INET6_ADDRSTRLEN
);
port
=
ntohs
(
((
struct
sockaddr_in6
*
)
&
sa
)
->
sin6_port
);
// Store the address for retrieval by users using wildcards
*
len
=
sprintf
((
char
*
)
*
addr
,
"tcp://[%s]:%d"
,
host
,
port
);
}
memcpy
(
addr
,
bound_addr
,
bound_addr_len
+
1
);
*
len
=
bound_addr_len
+
1
;
return
0
;
}
...
...
@@ -193,25 +212,6 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
return
-
1
;
#endif
struct
sockaddr
sa
;
socklen_t
sl
=
sizeof
(
sockaddr
);
rc
=
getsockname
(
s
,
&
sa
,
&
sl
);
if
(
rc
==
0
)
{
char
host
[
INET6_ADDRSTRLEN
];
int
port
;
if
(
sa
.
sa_family
==
AF_INET
)
{
inet_ntop
(
AF_INET
,
&
(((
struct
sockaddr_in
*
)
&
sa
)
->
sin_addr
),
host
,
INET6_ADDRSTRLEN
);
port
=
ntohs
(
((
struct
sockaddr_in
*
)
&
sa
)
->
sin_port
);
}
else
{
inet_ntop
(
AF_INET6
,
&
(((
struct
sockaddr_in6
*
)
&
sa
)
->
sin6_addr
),
host
,
INET6_ADDRSTRLEN
);
port
=
ntohs
(
((
struct
sockaddr_in6
*
)
&
sa
)
->
sin6_port
);
}
// Store the address for retrieval by users using wildcards
bound_addr_len
=
sprintf
(
bound_addr
,
"tcp://%s:%d"
,
host
,
port
);
}
// Listen for incomming connections.
rc
=
listen
(
s
,
options
.
backlog
);
#ifdef ZMQ_HAVE_WINDOWS
...
...
src/tcp_listener.hpp
View file @
770f8433
...
...
@@ -45,7 +45,7 @@ namespace zmq
// Set address to listen on.
int
set_address
(
const
char
*
addr_
);
// Get the bound address for use with wildcard
s
// Get the bound address for use with wildcard
int
get_address
(
unsigned
char
*
addr
,
size_t
*
len
);
private
:
...
...
@@ -67,10 +67,6 @@ namespace zmq
// Address to listen on.
tcp_address_t
address
;
// Store the connected endpoint for binds to port 0
char
bound_addr
[
256
];
size_t
bound_addr_len
;
// True, if the undelying file for UNIX domain socket exists.
bool
has_file
;
...
...
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