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
a7032e9c
Commit
a7032e9c
authored
Apr 28, 2013
by
Martin Hurton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update test_raw_sock to work with ZMTP/3.0
parent
cd4d8bb1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
16 deletions
+41
-16
test_raw_sock.cpp
tests/test_raw_sock.cpp
+41
-16
No files found.
tests/test_raw_sock.cpp
View file @
a7032e9c
...
...
@@ -28,9 +28,10 @@
typedef
unsigned
char
byte
;
typedef
struct
{
byte
signature
[
10
];
// 0xFF 8*0x00 0x7F
byte
revision
;
// 2 = ZMTP/2.1
byte
socktype
;
// Defined in ZMTP spec
byte
identity
[
2
];
// Empty message
byte
version
[
2
];
// 0x03 0x00 for ZMTP/3.0
byte
mechanism
[
20
];
// "NULL"
byte
as_server
;
byte
filler
[
31
];
}
zmtp_greeting_t
;
#define ZMTP_DEALER 5 // Socket type constants
...
...
@@ -40,7 +41,7 @@ typedef struct {
// 8-byte size is set to 1 for backwards compatibility
static
zmtp_greeting_t
greeting
=
{
{
0xFF
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
0x7F
},
2
,
0
,
{
0
,
0
}
};
=
{
{
0xFF
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
0x7F
},
{
3
,
0
},
{
'N'
,
'U'
,
'L'
,
'L'
}
};
int
main
(
void
)
{
...
...
@@ -91,7 +92,6 @@ int main (void)
// Send our own protocol greeting
rc
=
zmq_msg_send
(
&
identity
,
router
,
ZMQ_SNDMORE
);
assert
(
rc
>
0
);
greeting
.
socktype
=
ZMTP_ROUTER
;
rc
=
zmq_send
(
router
,
&
greeting
,
sizeof
(
greeting
),
0
);
assert
(
rc
==
sizeof
(
greeting
));
...
...
@@ -101,22 +101,47 @@ int main (void)
assert
(
rc
>
0
);
assert
(
zmq_msg_more
(
&
identity
));
// Second frame contains all remaining data from DEALER
// Second frame contains the rest of greeting along with
// the Ready command
rc
=
zmq_recv
(
router
,
buffer
,
255
,
0
);
assert
(
rc
==
11
);
assert
(
rc
==
99
);
// First
four bytes are [revision][socktype][identity]
assert
(
buffer
[
0
]
==
2
);
// ZMTP/2.1
assert
(
buffer
[
1
]
==
ZMTP_DEALER
);
// First
two bytes are major and minor version numbers.
assert
(
buffer
[
0
]
==
3
);
// ZMTP/3.0
assert
(
buffer
[
1
]
==
0
);
// Identity is 2 byte message
assert
(
buffer
[
2
]
==
0
);
// Flags = 0
assert
(
buffer
[
3
]
==
0
);
// Size = 0
// Mechanism is "NULL"
assert
(
memcmp
(
buffer
+
2
,
"NULL
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
"
,
22
)
==
0
);
assert
(
memcmp
(
buffer
+
54
,
"
\0\53
READY "
,
10
)
==
0
);
assert
(
memcmp
(
buffer
+
64
,
"
\13
Socket-Type
\0\0\0\6
DEALER"
,
22
)
==
0
);
assert
(
memcmp
(
buffer
+
86
,
"
\10
Identity
\0\0\0\0
"
,
13
)
==
0
);
// Announce we are ready
memcpy
(
buffer
,
"
\0\53
"
,
2
);
memcpy
(
buffer
+
2
,
"READY "
,
8
);
memcpy
(
buffer
+
10
,
"
\13
Socket-Type
\0\0\0\6
ROUTER"
,
22
);
memcpy
(
buffer
+
32
,
"
\10
Identity
\0\0\0\0
"
,
13
);
// Send Ready command
rc
=
zmq_msg_send
(
&
identity
,
router
,
ZMQ_SNDMORE
);
assert
(
rc
>
0
);
rc
=
zmq_send
(
router
,
buffer
,
45
,
0
);
assert
(
rc
==
45
);
// Now we expect the data from the DEALER socket
// First frame is, again, the identity of the connection
rc
=
zmq_msg_recv
(
&
identity
,
router
,
0
);
assert
(
rc
>
0
);
assert
(
zmq_msg_more
(
&
identity
));
// Third frame contains Hello message from DEALER
rc
=
zmq_recv
(
router
,
buffer
,
sizeof
buffer
,
0
);
assert
(
rc
==
7
);
// Then we have a 5-byte message "Hello"
assert
(
buffer
[
4
]
==
0
);
// Flags = 0
assert
(
buffer
[
5
]
==
5
);
// Size = 5
assert
(
memcmp
(
buffer
+
6
,
"Hello"
,
5
)
==
0
);
assert
(
buffer
[
0
]
==
0
);
// Flags = 0
assert
(
buffer
[
1
]
==
5
);
// Size = 5
assert
(
memcmp
(
buffer
+
2
,
"Hello"
,
5
)
==
0
);
// Send "World" back to DEALER
rc
=
zmq_msg_send
(
&
identity
,
router
,
ZMQ_SNDMORE
);
...
...
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