Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add test case for issue 308 and issue 309

  • Loading branch information...
commit 6a43ae349d54c3b72c6b77776a34c93c24c6313b 1 parent 87b53ba
@edmonds edmonds authored
View
22 308-309/README
@@ -0,0 +1,22 @@
+This test case requires a V2 publisher and a V3 subscriber, or a V3
+publisher and a V2 subscriber. The publisher connects and the
+subscriber binds.
+
+On my system, libzmq V2 is installed in /usr and libzmq V3 is installed
+in /usr/local. (The 'compile' script assumes these paths.)
+
+There are four test scripts ('test2-2', 'test2-3', 'test3-2', 'test3-3')
+that run the four possible combinations of (V2 publisher, V3 publisher)
+X (V2 subscriber, V3 subscriber).
+
+Here are the current results of all four combinations:
+
+ V2 publisher, V2 subscriber => success
+
+ V3 publisher, V3 subscriber => success
+
+ V2 publisher, V3 subscriber => V3 subscriber crashes with:
+ Assertion failed: options.recv_identity (socket_base.cpp:864)
+
+ V3 publisher, V2 subscriber => V3 publisher crashes with:
+ Assertion failed: size > 0 && (*data == 0 || *data == 1) (xpub.cpp:66)
View
13 308-309/compile
@@ -0,0 +1,13 @@
+#!/bin/sh -x
+
+# note: libzmq 2 installed into /usr, libzmq 3 installed into /usr/local
+
+CFLAGS="-Wall -O0 -ggdb"
+
+# compile against zmq2
+gcc -include /usr/include/zmq.h $CFLAGS -o pub2 pub.c -lzmq
+gcc -include /usr/include/zmq.h $CFLAGS -o sub2 sub.c -lzmq
+
+# compile against zmq3
+gcc -include /usr/local/include/zmq.h $CFLAGS -o pub3 pub.c -L/usr/local/lib -lzmq
+gcc -include /usr/local/include/zmq.h $CFLAGS -o sub3 sub.c -L/usr/local/lib -lzmq
View
80 308-309/pub.c
@@ -0,0 +1,80 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static int
+s_send(void *socket, char *string) {
+
+#if ZMQ_VERSION_MAJOR == 2
+
+ int rc;
+ zmq_msg_t message;
+ zmq_msg_init_size(&message, strlen(string));
+ memcpy(zmq_msg_data(&message), string, strlen(string));
+ rc = zmq_send(socket, &message, 0);
+ zmq_msg_close(&message);
+ return (rc);
+
+#elif ZMQ_VERSION_MAJOR == 3
+
+ return (zmq_send(socket, string, strlen(string), 0));
+
+#else
+# error "unknown ZeroMQ major version"
+#endif
+
+}
+
+void
+print_version(const char *s) {
+ int major, minor, patch;
+ zmq_version(&major, &minor, &patch);
+ printf("%s: zeromq version %d.%d.%d\n", s, major, minor, patch);
+}
+
+int main(int argc, char **argv) {
+ const char *str_socket;
+ void *context, *socket;
+
+ print_version("publisher");
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <SOCKET>\n", argv[0]);
+ return (EXIT_FAILURE);
+ }
+ str_socket = argv[1];
+
+ context = zmq_init(1);
+ if (!context) {
+ perror("zmq_init");
+ return (EXIT_FAILURE);
+ }
+
+ socket = zmq_socket(context, ZMQ_PUB);
+ if (!socket) {
+ perror("zmq_socket");
+ return (EXIT_FAILURE);
+ }
+
+ fprintf(stderr, "%s: connecting to socket %s\n", argv[0], str_socket);
+
+ if (zmq_connect(socket, str_socket)) {
+ perror("zmq_connect");
+ return (EXIT_FAILURE);
+ }
+
+ for (;;) {
+ char buf[512];
+
+ sprintf(buf, "hello %0x", (int) random());
+ s_send(socket, buf);
+ //printf("sent message: '%s'\n", buf);
+ sleep(1);
+ }
+
+ zmq_close(socket);
+ zmq_term(context);
+
+ return (EXIT_SUCCESS);
+}
View
88 308-309/sub.c
@@ -0,0 +1,88 @@
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static char *
+s_recv(void *socket) {
+ zmq_msg_t message;
+ zmq_msg_init(&message);
+#if ZMQ_VERSION_MAJOR == 2
+ if (zmq_recv(socket, &message, 0) != 0) {
+ perror("zmq_recv");
+ return (NULL);
+ }
+#elif ZMQ_VERSION_MAJOR == 3
+ if (zmq_recvmsg(socket, &message, 0) == -1) {
+ perror("zmq_recvmsg");
+ return (NULL);
+ }
+#else
+# error "unsupported ZeroMQ major version"
+#endif
+ int size = zmq_msg_size(&message);
+ char *string = malloc(size + 1);
+ memcpy(string, zmq_msg_data(&message), size);
+ zmq_msg_close(&message);
+ string[size] = 0;
+ return (string);
+}
+
+void
+print_version(const char *s) {
+ int major, minor, patch;
+ zmq_version(&major, &minor, &patch);
+ printf("%s: zeromq version %d.%d.%d\n", s, major, minor, patch);
+}
+
+int main(int argc, char **argv) {
+ const char *str_socket;
+ void *context, *socket;
+
+ print_version("subscriber");
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <SOCKET>\n", argv[0]);
+ return (EXIT_FAILURE);
+ }
+ str_socket = argv[1];
+
+ context = zmq_init(1);
+ if (!context) {
+ perror("zmq_init");
+ return (EXIT_FAILURE);
+ }
+
+ socket = zmq_socket(context, ZMQ_SUB);
+ if (!socket) {
+ perror("zmq_socket");
+ return (EXIT_FAILURE);
+ }
+
+ fprintf(stderr, "%s: binding to socket %s\n", argv[0], str_socket);
+
+ if (zmq_bind(socket, str_socket)) {
+ perror("zmq_bind");
+ return (EXIT_FAILURE);
+ }
+
+ if (zmq_setsockopt(socket, ZMQ_SUBSCRIBE, "", 0)) {
+ perror("zmq_setsockopt");
+ return (EXIT_FAILURE);
+ }
+
+ for (;;) {
+ char *string;
+
+ string = s_recv(socket);
+ printf("received message: '%s'\n", string);
+ free(string);
+ }
+
+ zmq_close(socket);
+ zmq_term(context);
+
+ return (EXIT_SUCCESS);
+}
View
4 308-309/test2-2
@@ -0,0 +1,4 @@
+#!/bin/sh -x
+
+./pub2 ipc://testcase2-2.ipc &
+./sub2 ipc://testcase2-2.ipc
View
4 308-309/test2-3
@@ -0,0 +1,4 @@
+#!/bin/sh -x
+
+./pub2 ipc://testcase2-3.ipc &
+./sub3 ipc://testcase2-3.ipc
View
4 308-309/test3-2
@@ -0,0 +1,4 @@
+#!/bin/sh -x
+
+./pub3 ipc://testcase3-2.ipc &
+./sub2 ipc://testcase3-2.ipc
View
4 308-309/test3-3
@@ -0,0 +1,4 @@
+#!/bin/sh -x
+
+./pub3 ipc://testcase3-3.ipc &
+./sub3 ipc://testcase3-3.ipc
Please sign in to comment.
Something went wrong with that request. Please try again.