-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getopt broken for nn_sub #51
Comments
right now we're subscribing to all msgs, i.e., the subscription key is an empty string. should that choice be determined by the user? |
@nickdesaulniers, we need to implement any socket subscription tracking at the JavaScript level. Nanomsg was not designed to keep track of that. And it looks like this was a deliberate choice: |
Also related is PR #37 . I'm getting a really bad feeling about this API. Apparently, you set a socket option on the subscriber, which allows it to ignore the first word in a message. I would have expected you to set the same topic on the publisher, but this is not the case. I'll need to spend more time figuring this out, but I really think this feature is broken upstream. At the bare minimum, the API makes it ambiguous for language binding maintainers to pass an test_case.c: // clang test_case.c -lnanomsg -o test_case && ./test_case
#include <pthread.h> // pthread_t, pthread_create, pthread_join
#include <stdio.h> // printf
#include <assert.h> // assert
#include <string.h> // strnlen, memset
#include <unistd.h> // usleep
#include "nanomsg/nn.h"
#include "nanomsg/pubsub.h"
// Shared memory
const char* addr = "tcp://127.0.0.1:7777";
//
void* publisher (void* data) {
printf("hello from publisher thread\n");
int sock = nn_socket(AF_SP, NN_PUB);
assert(sock >= 0);
assert(nn_bind(sock, addr) >= 0);
const char* msg1 = "topic.A hello world";
const char* msg2 = "topic.B goodbye world";
while (1) {
int bytes = nn_send(sock, msg1, strnlen(msg1, 200), 0);
printf("sent: %s\n", msg1);
bytes = nn_send(sock, msg2, strnlen(msg2, 200), 0);
printf("sent: %s\n", msg2);
/*usleep(10000); // 10ms*/
sleep(1);
}
nn_shutdown(sock, 0);
return NULL;
}
void* subscriber (void* data) {
printf("hello from subscriber thread\n");
int sock = nn_socket(AF_SP, NN_SUB);
assert(sock >= 0);
assert(nn_setsockopt(sock, NN_SUB, NN_SUB_SUBSCRIBE, "topic.A", 0) >= 0);
assert(nn_connect(sock, addr) >= 0);
char buf [200];
while (1) {
int bytes = nn_recv(sock, &buf, 200, 0);
printf("received: %s\n", buf);
/*nn_freemsg(&buf);*/
memset(&buf, 0, 200);
}
nn_shutdown(sock, 0);
return NULL;
}
int main () {
pthread_t p, s;
assert(pthread_create(&p, NULL, publisher, NULL) == 0);
assert(pthread_create(&s, NULL, subscriber, NULL) == 0);
assert(pthread_join(p, NULL) == 0);
assert(pthread_join(s, NULL) == 0);
} I would have expected the |
wait a minute, so with that code you're not able to receive |
With that code, I do receive msg2, so either filtering does not work, or does not work as I'm expecting. |
dupe #31 |
See the discussion here. This needs to be fixed: #46 (comment)
http://nanomsg.org/v0.2/nn_setsockopt.3.html
http://nanomsg.org/v0.2/nn_getsockopt.3.html
The text was updated successfully, but these errors were encountered: