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
de116425
Commit
de116425
authored
Jan 20, 2014
by
Tim M
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added test_connect_rid file and added to CMakeLists again.
parent
0e94ddf3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
0 deletions
+137
-0
CMakeLists.txt
CMakeLists.txt
+1
-0
test_connect_rid.cpp
tests/test_connect_rid.cpp
+136
-0
No files found.
CMakeLists.txt
View file @
de116425
...
...
@@ -622,6 +622,7 @@ set(tests
test_timeo
test_many_sockets
test_diffserv
test_connect_rid
)
if
(
NOT WIN32
)
list
(
APPEND tests
...
...
tests/test_connect_rid.cpp
0 → 100644
View file @
de116425
/*
Copyright (c) 2007-2014 Contributors as noted in the AUTHORS file
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "testutil.hpp"
void
test_stream_2_stream
(
void
*
ctx
){
void
*
rbind
,
*
rconn1
;
int
ret
;
char
buff
[
256
];
char
msg
[]
=
"hi 1"
;
const
char
*
bindip
=
"tcp://127.0.0.1:12001"
;
rbind
=
zmq_socket
(
ctx
,
ZMQ_STREAM
);
rconn1
=
zmq_socket
(
ctx
,
ZMQ_STREAM
);
assert
(
rbind
&&
rconn1
);
ret
=
zmq_bind
(
rbind
,
bindip
);
assert
(
0
==
ret
);
ret
=
zmq_setsockopt
(
rconn1
,
ZMQ_CONNECT_RID
,
"conn1"
,
6
);
assert
(
0
==
ret
);
ret
=
zmq_connect
(
rconn1
,
bindip
);
/*test duplicate connect attempt*/
ret
=
zmq_setsockopt
(
rconn1
,
ZMQ_CONNECT_RID
,
"conn1"
,
6
);
assert
(
0
==
ret
);
ret
=
zmq_connect
(
rconn1
,
bindip
);
assert
(
0
==
ret
);
ret
=
zmq_send
(
rconn1
,
"conn1"
,
6
,
ZMQ_SNDMORE
);
assert
(
6
==
ret
);
ret
=
zmq_send
(
rconn1
,
msg
,
5
,
0
);
assert
(
5
==
ret
);
ret
=
zmq_recv
(
rbind
,
buff
,
256
,
0
);
assert
(
ret
&&
0
==
buff
[
0
]);
ret
=
zmq_recv
(
rbind
,
buff
,
256
,
0
);
assert
(
0
==
ret
);
// close the duplicate socket
ret
=
zmq_recv
(
rbind
,
buff
,
256
,
0
);
assert
(
ret
&&
0
==
buff
[
0
]);
ret
=
zmq_recv
(
rbind
,
buff
+
128
,
128
,
0
);
assert
(
0
==
ret
);
// handle the good socket
ret
=
zmq_recv
(
rbind
,
buff
,
256
,
0
);
assert
(
ret
&&
0
==
buff
[
0
]);
ret
=
zmq_recv
(
rbind
,
buff
+
128
,
128
,
0
);
assert
(
5
==
ret
&&
'h'
==
buff
[
128
]
);
zmq_unbind
(
rbind
,
bindip
);
zmq_close
(
rbind
);
zmq_close
(
rconn1
);
}
void
test_router_2_router
(
void
*
ctx
,
bool
named
){
void
*
rbind
,
*
rconn1
;
int
ret
;
char
buff
[
256
];
char
msg
[]
=
"hi 1"
;
const
char
*
bindip
=
"tcp://127.0.0.1:12001"
;
rbind
=
zmq_socket
(
ctx
,
ZMQ_ROUTER
);
rconn1
=
zmq_socket
(
ctx
,
ZMQ_ROUTER
);
assert
(
rbind
&&
rconn1
);
ret
=
zmq_bind
(
rbind
,
bindip
);
assert
(
0
==
ret
);
if
(
named
){
/*here we check if this interferes with bound socket naming */
ret
=
zmq_setsockopt
(
rbind
,
ZMQ_IDENTITY
,
"X"
,
1
);
ret
=
zmq_setsockopt
(
rconn1
,
ZMQ_IDENTITY
,
"Y"
,
1
);
}
ret
=
zmq_setsockopt
(
rconn1
,
ZMQ_CONNECT_RID
,
"conn1"
,
6
);
assert
(
0
==
ret
);
ret
=
zmq_connect
(
rconn1
,
bindip
);
assert
(
0
==
ret
);
/*test duplicate connect attempt*/
ret
=
zmq_setsockopt
(
rconn1
,
ZMQ_CONNECT_RID
,
"conn1"
,
6
);
assert
(
0
==
ret
);
ret
=
zmq_connect
(
rconn1
,
bindip
);
assert
(
0
==
ret
);
ret
=
zmq_send
(
rconn1
,
"conn1"
,
6
,
ZMQ_SNDMORE
);
assert
(
6
==
ret
);
ret
=
zmq_send
(
rconn1
,
msg
,
5
,
0
);
assert
(
5
==
ret
);
ret
=
zmq_recv
(
rbind
,
buff
,
256
,
0
);
if
(
named
)
assert
(
ret
&&
'Y'
==
buff
[
0
]);
else
assert
(
ret
&&
0
==
buff
[
0
]);
ret
=
zmq_recv
(
rbind
,
buff
+
128
,
128
,
0
);
assert
(
5
==
ret
&&
'h'
==
buff
[
128
]
);
if
(
named
)
{
ret
=
zmq_send
(
rbind
,
buff
,
1
,
ZMQ_SNDMORE
);
assert
(
1
==
ret
);
}
else
{
ret
=
zmq_send
(
rbind
,
buff
,
5
,
ZMQ_SNDMORE
);
assert
(
5
==
ret
);
}
ret
=
zmq_send_const
(
rbind
,
"ok"
,
3
,
0
);
assert
(
3
==
ret
);
/*if bound socket identity naming a problem, we'll likely see something funky here */
ret
=
zmq_recv
(
rconn1
,
buff
,
256
,
0
);
assert
(
'c'
==
buff
[
0
]
&&
6
==
ret
);
ret
=
zmq_recv
(
rconn1
,
buff
+
128
,
128
,
0
);
assert
(
3
==
ret
&&
'o'
==
buff
[
128
]
);
zmq_unbind
(
rbind
,
bindip
);
zmq_close
(
rbind
);
zmq_close
(
rconn1
);
}
int
main
(
void
)
{
void
*
ctx
;
setup_test_environment
();
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
test_stream_2_stream
(
ctx
);
test_router_2_router
(
ctx
,
false
);
test_router_2_router
(
ctx
,
true
);
zmq_ctx_destroy
(
ctx
);
printf
(
"'test_connect_rid' passed"
);
return
0
;
}
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