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
34d5028e
Commit
34d5028e
authored
Apr 29, 2016
by
somdoron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow specify binding address on radio with udp
parent
9798f74d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
9 deletions
+20
-9
socket_base.cpp
src/socket_base.cpp
+1
-1
udp_address.cpp
src/udp_address.cpp
+16
-5
udp_address.hpp
src/udp_address.hpp
+1
-1
test_udp.cpp
tests/test_udp.cpp
+2
-2
No files found.
src/socket_base.cpp
View file @
34d5028e
...
...
@@ -882,7 +882,7 @@ int zmq::socket_base_t::connect (const char *addr_)
if
(
protocol
==
"udp"
)
{
paddr
->
resolved
.
udp_addr
=
new
(
std
::
nothrow
)
udp_address_t
();
alloc_assert
(
paddr
->
resolved
.
udp_addr
);
rc
=
paddr
->
resolved
.
udp_addr
->
resolve
(
address
.
c_str
());
rc
=
paddr
->
resolved
.
udp_addr
->
resolve
(
address
.
c_str
()
,
options
.
type
==
ZMQ_DISH
);
if
(
rc
!=
0
)
{
LIBZMQ_DELETE
(
paddr
);
EXIT_MUTEX
();
...
...
src/udp_address.cpp
View file @
34d5028e
...
...
@@ -58,7 +58,7 @@ zmq::udp_address_t::~udp_address_t ()
{
}
int
zmq
::
udp_address_t
::
resolve
(
const
char
*
name_
)
int
zmq
::
udp_address_t
::
resolve
(
const
char
*
name_
,
bool
receiver_
)
{
// Find the ':' at end that separates address from the port number.
const
char
*
delimiter
=
strrchr
(
name_
,
':'
);
...
...
@@ -80,7 +80,12 @@ int zmq::udp_address_t::resolve (const char *name_)
dest_address
.
sin_family
=
AF_INET
;
dest_address
.
sin_port
=
htons
(
port
);
dest_address
.
sin_addr
.
s_addr
=
inet_addr
(
addr_str
.
c_str
());
// Only when the udp is receiver we allow * as the address
if
(
addr_str
==
"*"
&&
receiver_
)
dest_address
.
sin_addr
.
s_addr
=
htons
(
INADDR_ANY
);
else
dest_address
.
sin_addr
.
s_addr
=
inet_addr
(
addr_str
.
c_str
());
if
(
dest_address
.
sin_addr
.
s_addr
==
INADDR_NONE
)
{
errno
=
EINVAL
;
...
...
@@ -104,9 +109,15 @@ int zmq::udp_address_t::resolve (const char *name_)
return
-
1
;
}
bind_address
.
sin_family
=
AF_INET
;
bind_address
.
sin_port
=
htons
(
port
);
bind_address
.
sin_addr
.
s_addr
=
htons
(
INADDR_ANY
);
// If a receiver and not a multicast, the dest address
// is actually the bind address
if
(
receiver_
&&
!
is_mutlicast
)
bind_address
=
dest_address
;
else
{
bind_address
.
sin_family
=
AF_INET
;
bind_address
.
sin_port
=
htons
(
port
);
bind_address
.
sin_addr
.
s_addr
=
htons
(
INADDR_ANY
);
}
address
=
name_
;
...
...
src/udp_address.hpp
View file @
34d5028e
...
...
@@ -48,7 +48,7 @@ namespace zmq
udp_address_t
();
virtual
~
udp_address_t
();
int
resolve
(
const
char
*
name_
);
int
resolve
(
const
char
*
name_
,
bool
receiver_
);
// The opposite to resolve()
virtual
int
to_string
(
std
::
string
&
addr_
);
...
...
tests/test_udp.cpp
View file @
34d5028e
...
...
@@ -95,10 +95,10 @@ int main (void)
void
*
radio
=
zmq_socket
(
ctx
,
ZMQ_RADIO
);
void
*
dish
=
zmq_socket
(
ctx
,
ZMQ_DISH
);
int
rc
=
zmq_
connect
(
radio
,
"udp://127.0.0.1
:5556"
);
int
rc
=
zmq_
bind
(
dish
,
"udp://*
:5556"
);
assert
(
rc
==
0
);
rc
=
zmq_
bind
(
dish
,
"udp://127.0.0.1:5556"
);
rc
=
zmq_
connect
(
radio
,
"udp://127.0.0.1:5556"
);
assert
(
rc
==
0
);
msleep
(
SETTLE_TIME
);
...
...
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