diff options
author | Thomas White <taw@physics.org> | 2021-04-22 15:53:56 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-04-23 14:57:24 +0200 |
commit | 2f4f6ad97467a62ed8bf5cb44040548b89493c0b (patch) | |
tree | 7e3e3ccd0c2087f75486844bdb179945affa703a /src/im-zmq.c | |
parent | 518a25b79026a17604c0430e1f0ed14954fe713a (diff) |
indexamajig: Add --zmq-subscribe
Diffstat (limited to 'src/im-zmq.c')
-rw-r--r-- | src/im-zmq.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/im-zmq.c b/src/im-zmq.c index 2f489811..be3bc544 100644 --- a/src/im-zmq.c +++ b/src/im-zmq.c @@ -55,9 +55,12 @@ struct im_zmq }; -struct im_zmq *im_zmq_connect(const char *zmq_address) +struct im_zmq *im_zmq_connect(const char *zmq_address, + char **subscriptions, + int n_subscriptions) { struct im_zmq *z; + int i; z = malloc(sizeof(struct im_zmq)); if ( z == NULL ) return NULL; @@ -73,11 +76,22 @@ struct im_zmq *im_zmq_connect(const char *zmq_address) ERROR("ZMQ connection failed: %s\n", zmq_strerror(errno)); return NULL; } - STATUS("ZMQ connected. Subscribing to 'ondaframedata'\n"); - if ( zmq_setsockopt(z->socket, ZMQ_SUBSCRIBE, "ondaframedata", 13) ) { - ERROR("ZMQ subscription failed: %s\n", zmq_strerror(errno)); - return NULL; + if ( n_subscriptions == 0 ) { + ERROR("WARNING: No ZeroMQ subscriptions. You should probably " + "try again with --zmq-subscribe.\n"); + } + + for ( i=0; i<n_subscriptions; i++ ) { + STATUS("Subscribing to '%s'\n", subscriptions[i]); + if ( zmq_setsockopt(z->socket, ZMQ_SUBSCRIBE, + subscriptions[i], + strlen(subscriptions[i])) ) + { + ERROR("ZMQ subscription failed: %s\n", + zmq_strerror(errno)); + return NULL; + } } return z; |