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
79d5ac3d
Unverified
Commit
79d5ac3d
authored
May 25, 2018
by
Luca Boccassi
Committed by
GitHub
May 25, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3135 from sigiesec/fix-heartbeat-ttl-max
Fix ZMQ_HEARTBEAT_TTL maximum value check
parents
50374bf6
76376098
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
2 deletions
+62
-2
zmq_setsockopt.txt
doc/zmq_setsockopt.txt
+1
-0
options.cpp
src/options.cpp
+4
-2
stdint.hpp
src/stdint.hpp
+3
-0
test_heartbeats.cpp
tests/test_heartbeats.cpp
+54
-0
No files found.
doc/zmq_setsockopt.txt
View file @
79d5ac3d
...
...
@@ -361,6 +361,7 @@ no effect.
Option value type:: int
Option value unit:: milliseconds
Default value:: 0
Maximum value:: 6553599 (which is 2^16-1 deciseconds)
Applicable socket types:: all, when using connection-oriented transports
...
...
src/options.cpp
View file @
79d5ac3d
...
...
@@ -282,6 +282,8 @@ int zmq::options_t::set_curve_key (uint8_t *destination,
return
-
1
;
}
const
int
deciseconds_per_millisecond
=
100
;
int
zmq
::
options_t
::
setsockopt
(
int
option_
,
const
void
*
optval_
,
size_t
optvallen_
)
...
...
@@ -665,8 +667,8 @@ int zmq::options_t::setsockopt (int option_,
case
ZMQ_HEARTBEAT_TTL
:
// Convert this to deciseconds from milliseconds
value
=
value
/
100
;
if
(
is_int
&&
value
>=
0
&&
value
<=
6553
)
{
value
=
value
/
deciseconds_per_millisecond
;
if
(
is_int
&&
value
>=
0
&&
value
<=
UINT16_MAX
)
{
heartbeat_ttl
=
static_cast
<
uint16_t
>
(
value
);
return
0
;
}
...
...
src/stdint.hpp
View file @
79d5ac3d
...
...
@@ -60,6 +60,9 @@ typedef unsigned __int32 uint32_t;
#ifndef uint64_t
typedef
unsigned
__int64
uint64_t
;
#endif
#ifndef UINT16_MAX
#define UINT16_MAX _UI16_MAX
#endif
#ifndef UINT32_MAX
#define UINT32_MAX _UI32_MAX
#endif
...
...
tests/test_heartbeats.cpp
View file @
79d5ac3d
...
...
@@ -29,6 +29,14 @@ typedef SOCKET raw_socket;
typedef
int
raw_socket
;
#endif
#include <limits.h>
// TODO remove this here, either ensure that UINT16_MAX is always properly
// defined or handle this at a more central location
#ifndef UINT16_MAX
#define UINT16_MAX 65535
#endif
#include "testutil_unity.hpp"
void
setUp
()
...
...
@@ -366,6 +374,48 @@ DEFINE_TESTS (pull, push, ZMQ_PULL, ZMQ_PUSH)
DEFINE_TESTS
(
sub
,
pub
,
ZMQ_SUB
,
ZMQ_PUB
)
DEFINE_TESTS
(
pair
,
pair
,
ZMQ_PAIR
,
ZMQ_PAIR
)
const
int
deciseconds_per_millisecond
=
100
;
const
int
heartbeat_ttl_max
=
(
UINT16_MAX
+
1
)
*
deciseconds_per_millisecond
-
1
;
void
test_setsockopt_heartbeat_success
(
const
int
value
)
{
void
*
const
socket
=
test_context_socket
(
ZMQ_PAIR
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
socket
,
ZMQ_HEARTBEAT_TTL
,
&
value
,
sizeof
(
value
)));
int
value_read
;
size_t
value_read_size
=
sizeof
(
value_read
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
socket
,
ZMQ_HEARTBEAT_TTL
,
&
value_read
,
&
value_read_size
));
TEST_ASSERT_EQUAL_INT
(
value
-
value
%
deciseconds_per_millisecond
,
value_read
);
test_context_socket_close
(
socket
);
}
void
test_setsockopt_heartbeat_ttl_max
()
{
test_setsockopt_heartbeat_success
(
heartbeat_ttl_max
);
}
void
test_setsockopt_heartbeat_ttl_more_than_max_fails
()
{
void
*
const
socket
=
test_context_socket
(
ZMQ_PAIR
);
const
int
value
=
heartbeat_ttl_max
+
1
;
TEST_ASSERT_FAILURE_ERRNO
(
EINVAL
,
zmq_setsockopt
(
socket
,
ZMQ_HEARTBEAT_TTL
,
&
value
,
sizeof
(
value
)));
test_context_socket_close
(
socket
);
}
void
test_setsockopt_heartbeat_ttl_near_zero
()
{
test_setsockopt_heartbeat_success
(
deciseconds_per_millisecond
-
1
);
}
int
main
(
void
)
{
setup_test_environment
();
...
...
@@ -381,6 +431,10 @@ int main (void)
RUN_TEST
(
test_heartbeat_ttl_sub_pub
);
RUN_TEST
(
test_heartbeat_ttl_pair_pair
);
RUN_TEST
(
test_setsockopt_heartbeat_ttl_max
);
RUN_TEST
(
test_setsockopt_heartbeat_ttl_more_than_max_fails
);
RUN_TEST
(
test_setsockopt_heartbeat_ttl_near_zero
);
RUN_TEST
(
test_heartbeat_notimeout_dealer_router
);
RUN_TEST
(
test_heartbeat_notimeout_req_rep
);
RUN_TEST
(
test_heartbeat_notimeout_pull_push
);
...
...
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