-
Notifications
You must be signed in to change notification settings - Fork 156
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
[Question] any thought on re-implementing some nanomsg protocol base on libdill? #156
Comments
@kingsrd I've been thinking about this for a while myself, and if I were to tackle this problem, I would keep them conceptually separate. Instead of implementing NNG/nanomsg/zeromq or similar on top of Then any IO implementation, including The more I think about it the more I think that the very idea of always implementing protocol logic and IO logic as one abstraction onion is worse than implementing them as two separately reusable abstractions that are agnostic of each other. |
Which I realize isn't really an answer to the question, and I've never contributed anything to But my point is that maybe asking about whether or not |
I think so @kingsrd. Also libmill. That's why Fatih Kaya @fatihky and I wrote the nnmill experiment We found these libraries incredibly useful and wanted to see whether you could send and recv nanomsg wire protocol while coordinating kernel I/O operations from simple and performant coroutines:
int nn_mill_getfd (int s, int fdtype) {
int rc, fd;
size_t fdsz = sizeof fd;
if ( nn_getsockopt (s, NN_SOL_SOCKET, fdtype, &fd, &fdsz) != 0 )
return -1;
return fd;
}
turns out you don't have to rewrite one line of nanomsg. nnmill experiment's int main(int argc, char *argv[]) {
int s = nn_socket(AF_SP, NN_PAIR);
int s2 = nn_socket(AF_SP, NN_PAIR);
int rc;
chan endch = chmake(int, 1);
nn_bind(s, "tcp://127.0.0.1:7458");
nn_connect(s2, "tcp://127.0.0.1:7458");
go(sender(s));
go(receiver(s2));
chr(endch, int);
return 0;
}
coroutine void sender(int s) {
int rc;
for(;;) {
rc = nm_send (s, "test", 4, 0, -1);
if (rc != 4)
break; // TODO: print error
msleep(now() + 1000);
}
}
coroutine void receiver(int s) {
char buf[5];
int rc;
buf[4] = '\0';
for(;;) {
rc = nm_recv (s, buf, 4, 0, -1);
if (rc != 4)
break; // TODO: print error
printf("recevied: %s\n", buf);
}
} What's int nm_recv (int s, void *buf, size_t len, int flags, int64_t deadline) {
int fd = nn_mill_getfd(s, NN_RCVFD);
int events;
int rc;
if (flags == NN_DONTWAIT)
return nn_recv(s, buf, len, flags);
events = fdwait(fd, FDW_IN, deadline);
if (!(events & FDW_IN))
return EAGAIN;
rc = nn_recv(s, buf, len, 0);
return rc;
} |
I want to use the nng with libdill, but I found the nng not work correctly in libdill environment.
Run output as follow:
The correct output should be:
I can not find the reason, please give some suggestion. |
I read about the motivation of NNG re-implementing nanomsg in addressing problems e.g. scalability/reliability because of the heavy use of state machine. Just out of curiosity (of your opinion), can libdill be a good candidate for re-implementing nanomsg?
The text was updated successfully, but these errors were encountered: