2
Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
4
This file is part of 0MQ.
6
0MQ is free software; you can redistribute it and/or modify it under
7
the terms of the GNU Lesser General Public License as published by
8
the Free Software Foundation; either version 3 of the License, or
9
(at your option) any later version.
11
0MQ is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "testutil.hpp"
22
const char *bind_address = 0;
23
const char *connect_address = 0;
25
void test_fair_queue_in (void *ctx)
27
void *rep = zmq_socket (ctx, ZMQ_REP);
31
int rc = zmq_setsockopt (rep, ZMQ_RCVTIMEO, &timeout, sizeof (int));
34
rc = zmq_bind (rep, bind_address);
37
const size_t services = 5;
38
void *reqs [services];
39
for (size_t peer = 0; peer < services; ++peer) {
40
reqs [peer] = zmq_socket (ctx, ZMQ_REQ);
43
rc = zmq_setsockopt (reqs [peer], ZMQ_RCVTIMEO, &timeout, sizeof (int));
46
rc = zmq_connect (reqs [peer], connect_address);
50
s_send_seq (reqs [0], "A", SEQ_END);
51
s_recv_seq (rep, "A", SEQ_END);
52
s_send_seq (rep, "A", SEQ_END);
53
s_recv_seq (reqs [0], "A", SEQ_END);
55
s_send_seq (reqs [0], "A", SEQ_END);
56
s_recv_seq (rep, "A", SEQ_END);
57
s_send_seq (rep, "A", SEQ_END);
58
s_recv_seq (reqs [0], "A", SEQ_END);
60
// TODO: following test fails randomly on some boxes
61
#ifdef SOMEONE_FIXES_THIS
63
for (size_t peer = 0; peer < services; ++peer) {
64
char * str = strdup("A");
66
s_send_seq (reqs [peer], str, SEQ_END);
71
for (size_t peer = 0; peer < services; ++peer) {
72
char * str = strdup("A");
75
s_recv_seq (rep, str, SEQ_END);
76
s_send_seq (rep, str, SEQ_END);
77
s_recv_seq (reqs [peer], str, SEQ_END);
81
close_zero_linger (rep);
83
for (size_t peer = 0; peer < services; ++peer)
84
close_zero_linger (reqs [peer]);
86
// Wait for disconnects.
87
rc = zmq_poll (0, 0, 100);
91
void test_envelope (void *ctx)
93
void *rep = zmq_socket (ctx, ZMQ_REP);
96
int rc = zmq_bind (rep, bind_address);
99
void *dealer = zmq_socket (ctx, ZMQ_DEALER);
102
rc = zmq_connect (dealer, connect_address);
106
s_send_seq (dealer, 0, "A", SEQ_END);
107
s_recv_seq (rep, "A", SEQ_END);
108
s_send_seq (rep, "A", SEQ_END);
109
s_recv_seq (dealer, 0, "A", SEQ_END);
112
s_send_seq (dealer, "X", "Y", 0, "A", SEQ_END);
113
s_recv_seq (rep, "A", SEQ_END);
114
s_send_seq (rep, "A", SEQ_END);
115
s_recv_seq (dealer, "X", "Y", 0, "A", SEQ_END);
117
close_zero_linger (rep);
118
close_zero_linger (dealer);
120
// Wait for disconnects.
121
rc = zmq_poll (0, 0, 100);
127
setup_test_environment();
128
void *ctx = zmq_ctx_new ();
131
const char *binds [] = { "inproc://a", "tcp://127.0.0.1:5555" };
132
const char *connects [] = { "inproc://a", "tcp://localhost:5555" };
134
for (int transport = 0; transport < 2; ++transport) {
135
bind_address = binds [transport];
136
connect_address = connects [transport];
138
// SHALL receive incoming messages from its peers using a fair-queuing
140
test_fair_queue_in (ctx);
142
// For an incoming message:
143
// SHALL remove and store the address envelope, including the delimiter.
144
// SHALL pass the remaining data frames to its calling application.
145
// SHALL wait for a single reply message from its calling application.
146
// SHALL prepend the address envelope and delimiter.
147
// SHALL deliver this message back to the originating peer.
151
int rc = zmq_ctx_term (ctx);