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
0a037a74
Unverified
Commit
0a037a74
authored
May 14, 2018
by
Luca Boccassi
Committed by
GitHub
May 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3097 from sigiesec/ping-context
ZMTP 3.1 PING Context not implemented
parents
df2fe88b
be66eacf
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
8 deletions
+64
-8
Makefile.am
Makefile.am
+2
-1
stream_engine.cpp
src/stream_engine.cpp
+34
-7
stream_engine.hpp
src/stream_engine.hpp
+3
-0
test_heartbeats.cpp
tests/test_heartbeats.cpp
+0
-0
testutil_unity.hpp
tests/testutil_unity.hpp
+25
-0
No files found.
Makefile.am
View file @
0a037a74
...
...
@@ -651,7 +651,8 @@ tests_test_setsockopt_SOURCES = tests/test_setsockopt.cpp
tests_test_setsockopt_LDADD
=
src/libzmq.la
tests_test_heartbeats_SOURCES
=
tests/test_heartbeats.cpp
tests_test_heartbeats_LDADD
=
src/libzmq.la
tests_test_heartbeats_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_heartbeats_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_stream_exceeds_buffer_SOURCES
=
tests/test_stream_exceeds_buffer.cpp
tests_test_stream_exceeds_buffer_LDADD
=
src/libzmq.la
...
...
src/stream_engine.cpp
View file @
0a037a74
...
...
@@ -98,6 +98,8 @@ zmq::stream_engine_t::stream_engine_t (fd_t fd_,
{
int
rc
=
tx_msg
.
init
();
errno_assert
(
rc
==
0
);
rc
=
pong_msg
.
init
();
errno_assert
(
rc
==
0
);
// Put the socket into non-blocking mode.
unblock_socket
(
s
);
...
...
@@ -935,9 +937,7 @@ int zmq::stream_engine_t::decode_and_push (msg_t *msg_)
}
if
(
msg_
->
flags
()
&
msg_t
::
command
)
{
uint8_t
cmd_id
=
*
((
uint8_t
*
)
msg_
->
data
());
if
(
cmd_id
==
4
)
process_heartbeat_message
(
msg_
);
process_command_message
(
msg_
);
}
if
(
metadata
)
...
...
@@ -1061,11 +1061,8 @@ int zmq::stream_engine_t::produce_pong_message (msg_t *msg_)
int
rc
=
0
;
zmq_assert
(
mechanism
!=
NULL
);
rc
=
msg_
->
init_size
(
5
);
rc
=
msg_
->
move
(
pong_msg
);
errno_assert
(
rc
==
0
);
msg_
->
set_flags
(
msg_t
::
command
);
memcpy
(
msg_
->
data
(),
"
\4
PONG"
,
5
);
rc
=
mechanism
->
encode
(
msg_
);
next_msg
=
&
stream_engine_t
::
pull_and_encode
;
...
...
@@ -1088,9 +1085,39 @@ int zmq::stream_engine_t::process_heartbeat_message (msg_t *msg_)
has_ttl_timer
=
true
;
}
// As per ZMTP 3.1 the PING command might contain an up to 16 bytes
// context which needs to be PONGed back, so build the pong message
// here and store it. Truncate it if it's too long.
// Given the engine goes straight to out_event, sequential PINGs will
// not be a problem.
size_t
context_len
=
msg_
->
size
()
-
7
>
16
?
16
:
msg_
->
size
()
-
7
;
int
rc
=
pong_msg
.
init_size
(
5
+
context_len
);
errno_assert
(
rc
==
0
);
pong_msg
.
set_flags
(
msg_t
::
command
);
memcpy
(
pong_msg
.
data
(),
"
\4
PONG"
,
5
);
if
(
context_len
>
0
)
memcpy
(((
uint8_t
*
)
pong_msg
.
data
())
+
5
,
((
uint8_t
*
)
msg_
->
data
())
+
7
,
context_len
);
next_msg
=
&
stream_engine_t
::
produce_pong_message
;
out_event
();
}
return
0
;
}
int
zmq
::
stream_engine_t
::
process_command_message
(
msg_t
*
msg_
)
{
uint8_t
cmd_name_size
=
*
((
uint8_t
*
)
msg_
->
data
());
// Malformed command
if
(
msg_
->
size
()
<
cmd_name_size
+
sizeof
(
cmd_name_size
))
return
-
1
;
uint8_t
*
cmd_name
=
((
uint8_t
*
)
msg_
->
data
())
+
1
;
if
(
cmd_name_size
==
4
&&
(
memcmp
(
cmd_name
,
"PING"
,
cmd_name_size
)
==
0
||
memcmp
(
cmd_name
,
"PONG"
,
cmd_name_size
)
==
0
))
return
process_heartbeat_message
(
msg_
);
return
0
;
}
src/stream_engine.hpp
View file @
0a037a74
...
...
@@ -127,6 +127,7 @@ class stream_engine_t : public io_object_t, public i_engine
typedef
metadata_t
::
dict_t
properties_t
;
bool
init_properties
(
properties_t
&
properties
);
int
process_command_message
(
msg_t
*
msg_
);
int
produce_ping_message
(
msg_t
*
msg_
);
int
process_heartbeat_message
(
msg_t
*
msg_
);
int
produce_pong_message
(
msg_t
*
msg_
);
...
...
@@ -138,6 +139,8 @@ class stream_engine_t : public io_object_t, public i_engine
bool
as_server
;
msg_t
tx_msg
;
// Need to store PING payload for PONG
msg_t
pong_msg
;
handle_t
handle
;
...
...
tests/test_heartbeats.cpp
View file @
0a037a74
This diff is collapsed.
Click to expand it.
tests/testutil_unity.hpp
View file @
0a037a74
...
...
@@ -57,12 +57,37 @@ int test_assert_success_message_errno_helper (int rc,
return
rc
;
}
int
test_assert_success_message_raw_errno_helper
(
int
rc
,
const
char
*
msg
,
const
char
*
expr
)
{
if
(
rc
==
-
1
)
{
#if defined ZMQ_HAVE_WINDOWS
int
current_errno
=
WSAGetLastError
();
#else
int
current_errno
=
errno
;
#endif
char
buffer
[
512
];
buffer
[
sizeof
(
buffer
)
-
1
]
=
0
;
// to ensure defined behavior with VC++ <= 2013
snprintf
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%s failed%s%s%s, errno = %i"
,
expr
,
msg
?
" (additional info: "
:
""
,
msg
?
msg
:
""
,
msg
?
")"
:
""
,
current_errno
);
TEST_FAIL_MESSAGE
(
buffer
);
}
return
rc
;
}
#define TEST_ASSERT_SUCCESS_MESSAGE_ERRNO(expr, msg) \
test_assert_success_message_errno_helper (expr, msg, #expr)
#define TEST_ASSERT_SUCCESS_ERRNO(expr) \
test_assert_success_message_errno_helper (expr, NULL, #expr)
#define TEST_ASSERT_SUCCESS_RAW_ERRNO(expr) \
test_assert_success_message_raw_errno_helper (expr, NULL, #expr)
#define TEST_ASSERT_FAILURE_ERRNO(error_code, expr) \
{ \
int rc = (expr); \
...
...
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