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
8dbda15e
Commit
8dbda15e
authored
Jan 30, 2016
by
Constantin Rack
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1745 from somdoron/master
parents
4f4e4753
389e853c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
14 deletions
+36
-14
udp_address.cpp
src/udp_address.cpp
+1
-5
udp_engine.cpp
src/udp_engine.cpp
+31
-7
test_radio_dish.cpp
tests/test_radio_dish.cpp
+1
-0
test_udp.cpp
tests/test_udp.cpp
+3
-2
No files found.
src/udp_address.cpp
View file @
8dbda15e
...
...
@@ -49,6 +49,7 @@
zmq
::
udp_address_t
::
udp_address_t
()
{
memset
(
&
bind_address
,
0
,
sizeof
bind_address
);
memset
(
&
dest_address
,
0
,
sizeof
dest_address
);
}
zmq
::
udp_address_t
::~
udp_address_t
()
...
...
@@ -68,11 +69,6 @@ int zmq::udp_address_t::resolve (const char *name_)
std
::
string
addr_str
(
name_
,
delimiter
-
name_
);
std
::
string
port_str
(
delimiter
+
1
);
// Remove square brackets around the address, if any, as used in IPv6
if
(
addr_str
.
size
()
>=
2
&&
addr_str
[
0
]
==
'['
&&
addr_str
[
addr_str
.
size
()
-
1
]
==
']'
)
addr_str
=
addr_str
.
substr
(
1
,
addr_str
.
size
()
-
2
);
// Parse the port number (0 is not a valid port).
uint16_t
port
=
(
uint16_t
)
atoi
(
port_str
.
c_str
());
if
(
port
==
0
)
{
...
...
src/udp_engine.cpp
View file @
8dbda15e
...
...
@@ -91,7 +91,7 @@ void zmq::udp_engine_t::plug (io_thread_t* io_thread_, session_base_t *session_)
mreq
.
imr_multiaddr
=
address
->
resolved
.
udp_addr
->
multicast_ip
();
mreq
.
imr_interface
=
address
->
resolved
.
udp_addr
->
interface_ip
();
int
rc
=
setsockopt
(
fd
,
IPPROTO_IP
,
IP_ADD_MEMBERSHIP
,
&
mreq
,
sizeof
(
mreq
));
int
rc
=
setsockopt
(
fd
,
IPPROTO_IP
,
IP_ADD_MEMBERSHIP
,
(
char
*
)
&
mreq
,
sizeof
(
mreq
));
#ifdef ZMQ_HAVE_WINDOWS
wsa_assert
(
rc
!=
SOCKET_ERROR
);
...
...
@@ -145,10 +145,17 @@ void zmq::udp_engine_t::out_event()
body_msg
.
close
();
errno_assert
(
rc
==
0
);
#ifdef ZMQ_HAVE_WINDOWS
rc
=
sendto
(
fd
,
(
char
*
)
out_buffer
,
size
,
0
,
address
->
resolved
.
udp_addr
->
dest_addr
(),
address
->
resolved
.
udp_addr
->
dest_addrlen
());
wsa_assert
(
rc
!=
SOCKET_ERROR
);
#else
rc
=
sendto
(
fd
,
out_buffer
,
size
,
0
,
address
->
resolved
.
udp_addr
->
dest_addr
(),
address
->
resolved
.
udp_addr
->
dest_addrlen
());
errno_assert
(
rc
!=
-
1
);
#endif
}
else
reset_pollout
(
handle
);
...
...
@@ -170,16 +177,34 @@ void zmq::udp_engine_t::restart_output()
void
zmq
::
udp_engine_t
::
in_event
()
{
size_t
read
=
recv
(
fd
,
in_buffer
,
MAX_UDP_MSG
,
0
);
#ifdef ZMQ_HAVE_WINDOWS
int
nbytes
=
recv
(
fd
,
(
char
*
)
in_buffer
,
MAX_UDP_MSG
,
0
);
const
int
last_error
=
WSAGetLastError
();
if
(
nbytes
==
SOCKET_ERROR
)
{
wsa_assert
(
last_error
==
WSAENETDOWN
||
last_error
==
WSAENETRESET
||
last_error
==
WSAEWOULDBLOCK
);
return
;
}
#else
int
nbytes
=
recv
(
fd
,
in_buffer
,
MAX_UDP_MSG
,
0
);
if
(
nbytes
==
-
1
)
{
errno_assert
(
errno
!=
EBADF
&&
errno
!=
EFAULT
&&
errno
!=
ENOMEM
&&
errno
!=
ENOTSOCK
);
return
;
}
#endif
if
(
read
>
0
)
{
size_t
group_size
=
in_buffer
[
0
];
int
group_size
=
in_buffer
[
0
];
// This doesn't fit, just ingore
if
(
read
-
1
<
group_size
)
if
(
nbytes
-
1
<
group_size
)
return
;
size_t
body_size
=
read
-
1
-
group_size
;
int
body_size
=
nbytes
-
1
-
group_size
;
msg_t
msg
;
int
rc
=
msg
.
init_size
(
group_size
);
...
...
@@ -209,7 +234,6 @@ void zmq::udp_engine_t::in_event()
rc
=
msg
.
close
();
errno_assert
(
rc
==
0
);
session
->
flush
();
}
}
void
zmq
::
udp_engine_t
::
restart_input
()
...
...
tests/test_radio_dish.cpp
View file @
8dbda15e
...
...
@@ -77,6 +77,7 @@ int msg_recv_cmp (zmq_msg_t *msg_, void *s_, const char* group_, const char* bod
}
zmq_msg_close
(
msg_
);
free
(
body
);
return
recv_rc
;
}
...
...
tests/test_udp.cpp
View file @
8dbda15e
...
...
@@ -77,6 +77,7 @@ int msg_recv_cmp (zmq_msg_t *msg_, void *s_, const char* group_, const char* bod
}
zmq_msg_close
(
msg_
);
free
(
body
);
return
recv_rc
;
}
...
...
@@ -91,10 +92,10 @@ int main (void)
void
*
radio
=
zmq_socket
(
ctx
,
ZMQ_RADIO
);
void
*
dish
=
zmq_socket
(
ctx
,
ZMQ_DISH
);
int
rc
=
zmq_
bind
(
radio
,
"udp://127.0.0.1:5556"
);
int
rc
=
zmq_
connect
(
radio
,
"udp://127.0.0.1:5556"
);
assert
(
rc
==
0
);
rc
=
zmq_
connect
(
dish
,
"udp://127.0.0.1:5556"
);
rc
=
zmq_
bind
(
dish
,
"udp://127.0.0.1:5556"
);
assert
(
rc
==
0
);
zmq_sleep
(
1
);
...
...
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