Skip to content
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

nng not work correctly in libdill environment #941

Open
szyusong opened this issue May 16, 2019 · 2 comments
Open

nng not work correctly in libdill environment #941

szyusong opened this issue May 16, 2019 · 2 comments

Comments

@szyusong
Copy link

I want to use the nng with libdill, but I found the nng not work correctly in libdill environment.

static dill_coroutine void
test_pub(void)
{
  nng_socket sock;
  nng_msg *msg;
  int ret;

  nng_pub0_open(&sock);

  nng_listen(sock, "ipc:///tmp/pub_sub.ipc", NULL, 0);

  while(1)
  {
    ret = nng_send(sock, "1", 1, 0);
    printf("1: %d\n", ret);

    ret = nng_send(sock, "12", 2, 0);
    printf("2: %d\n", ret);

    ret = nng_send(sock, "123", 3, 0);
    printf("3: %d\n", ret);

    ret = nng_send(sock, "1234", 4, 0);
    printf("4: %d\n", ret);

    dill_msleep(dill_now() + 1000);
  }
}

static dill_coroutine void
test_sub(void)
{
  nng_socket sock;
  int fd, ret;
  nng_msg *msg;
  uint8_t *buf;
  size_t sz;

  nng_sub0_open(&sock);

  nng_setopt(sock, NNG_OPT_SUB_SUBSCRIBE, "", 0);

  nng_dial(sock, "ipc:///tmp/pub_sub.ipc", NULL, 0);

  nng_getopt_int(sock, NNG_OPT_RECVFD, &fd);

  while(dill_fdin(fd, -1) >= 0)
  {
    nng_recv(sock, &buf, &sz, NNG_FLAG_NONBLOCK | NNG_FLAG_ALLOC);
    printf("recv: %d\n", sz);
    nng_free(buf, sz);
  }
}

int
main(void)
{
  dill_go(test_pub());
  dill_go(test_sub());
  dill_msleep(-1);

  return 0;
}

Run output as follow:

1: 0
2: 0
3: 0
4: 0
1: 0
2: 0
3: 0
4: 0
recv: 1
1: 0
2: 0
3: 0
4: 0
recv: 1
recv: 3
1: 0
2: 0
3: 0
4: 0
recv: 1
recv: 3
1: 0
2: 0
3: 0
4: 0
recv: 1
1: 0
2: 0
3: 0
4: 0
recv: 1
1: 0
2: 0
3: 0
4: 0
recv: 1
...

The correct output should be:

1: 0
2: 0
3: 0
4: 0
recv: 1
recv: 2
recv: 3
recv: 4
1: 0
2: 0
3: 0
4: 0
recv: 1
recv: 2
recv: 3
recv: 4
...

I can not find the reason, please give some suggestion.

@skull-squadron
Copy link

Unable to reproduce: Not enough data and not a minimal complete example.

Also, print what is received and what should be received to aid debugging.

macOS 10.14.5
libdill 2.14
nng 1.1.1 or master @ 7eaccab

1: 0
2: 0
3: 0
4: 0
1: 0
2: 0
3: 0
4: 0
recv: 1
recv: 2
recv: 3
recv: 4
1: 0
2: 0
3: 0
4: 0
recv: 1
recv: 2
recv: 3
recv: 4
1: 0
2: 0
3: 0
4: 0
recv: 1
recv: 2
recv: 3
recv: 4
^C

@gdamore
Copy link
Contributor

gdamore commented May 19, 2019

As I have already communicated out of band, NNG currently relies on system threads for some things, and is not compatible with libdill. It was designed to be able to be easily ported to libdill, and that could be done, but it would require a modest amount of effort to do that port. (Essentially, libdill would be like a new platform port, at least where the threading and synchronization primitives are concerned.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants