diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-22 02:32:32 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-22 02:32:32 -0800 |
| commit | b93d5759c9b39ff153a14d474d800cd981f7dc97 (patch) | |
| tree | 1a98b7ac74cd91003c38f53ae3eb01fb8027deef /tests | |
| parent | 769f9a2b66aca629eb4dd240a072849a48aa300f (diff) | |
| download | nng-b93d5759c9b39ff153a14d474d800cd981f7dc97.tar.gz nng-b93d5759c9b39ff153a14d474d800cd981f7dc97.tar.bz2 nng-b93d5759c9b39ff153a14d474d800cd981f7dc97.zip | |
Event notification via pollable FDs verified working.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/event.c | 21 | ||||
| -rw-r--r-- | tests/pollfd.c | 73 |
2 files changed, 77 insertions, 17 deletions
diff --git a/tests/event.c b/tests/event.c index 554f990f..4e6eae8c 100644 --- a/tests/event.c +++ b/tests/event.c @@ -33,28 +33,28 @@ bump(nng_event *ev, void *arg) assert(nng_event_socket(ev) == cnt->sock); switch (nng_event_type(ev)) { - case NNG_EV_CAN_SEND: - cnt->writeable++; + case NNG_EV_CAN_SND: + cnt->writeable = 1; break; - case NNG_EV_CAN_RECV: - cnt->readable++; + case NNG_EV_CAN_RCV: + cnt->readable = 1; break; case NNG_EV_PIPE_ADD: - cnt->pipeadd++; + cnt->pipeadd = 1; break; case NNG_EV_PIPE_REM: - cnt->piperem++; + cnt->piperem = 1; break; case NNG_EV_ENDPT_ADD: - cnt->epadd++; + cnt->epadd = 1; break; case NNG_EV_ENDPT_REM: - cnt->eprem++; + cnt->eprem = 1; break; default: @@ -95,8 +95,8 @@ Main({ nng_usleep(100000); Convey("We can register callbacks", { - So((notify1 = nng_setnotify(sock1, NNG_EV_CAN_SEND, bump, &evcnt1)) != NULL); - So((notify2 = nng_setnotify(sock2, NNG_EV_CAN_RECV, bump, &evcnt2)) != NULL); + So((notify1 = nng_setnotify(sock1, NNG_EV_CAN_SND, bump, &evcnt1)) != NULL); + So((notify2 = nng_setnotify(sock2, NNG_EV_CAN_RCV, bump, &evcnt2)) != NULL); Convey("They are called", { nng_msg *msg; @@ -105,6 +105,7 @@ Main({ APPENDSTR(msg, "abc"); So(nng_sendmsg(sock1, msg, 0) == 0); + //nng_usleep(20000); So(nng_recvmsg(sock2, &msg, 0) == 0); CHECKSTR(msg, "abc"); diff --git a/tests/pollfd.c b/tests/pollfd.c index 899547c6..f6b9cf30 100644 --- a/tests/pollfd.c +++ b/tests/pollfd.c @@ -10,12 +10,22 @@ #include "convey.h" #include "nng.h" -#ifdef _WIN32 -#include <windows.h> -#include <winsock2.h> -#else +#ifndef _WIN32 #include <unistd.h> +#include <poll.h> #define INVALID_SOCKET -1 +#else + +#define poll WSAPoll +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include <windows.h> +#include <winsock2.h> +#include <mswsock.h> +#include <ws2tcpip.h> + #endif // Inproc tests. @@ -33,15 +43,39 @@ TestMain("Poll FDs", { nng_close(s2); }) So(nng_listen(s1, "inproc://yeahbaby", NULL, 0) == 0); - So(nng_dial(s2, "inproc://yeahbaby", NULL, NNG_FLAG_SYNCH) == 0); + nng_usleep(50000); + + So(nng_dial(s2, "inproc://yeahbaby", NULL, 0) == 0); + nng_usleep(50000); Convey("We can get a recv FD", { int fd; size_t sz; sz = sizeof (fd); - So(nng_getopt(s1, NNG_OPT_RECVFD, &fd, &sz) == 0); + So(nng_getopt(s1, NNG_OPT_RCVFD, &fd, &sz) == 0); So(fd != INVALID_SOCKET); + + Convey("And they start non pollable", { + struct pollfd pfd; + pfd.fd = fd; + pfd.events = POLLIN; + pfd.revents = 0; + + So(poll(&pfd, 1, 0) == 0); + So(pfd.revents == 0); + }) + + Convey("But if we write they are pollable", { + struct pollfd pfd; + pfd.fd = fd; + pfd.events = POLLIN; + pfd.revents = 0; + + So(nng_send(s2, "kick", 5, 0) == 0); + So(poll(&pfd, 1, 1000) == 1); + So((pfd.revents & POLLIN) != 0); + }) }) Convey("We can get a send FD", { @@ -49,8 +83,33 @@ TestMain("Poll FDs", { size_t sz; sz = sizeof (fd); - So(nng_getopt(s1, NNG_OPT_SENDFD, &fd, &sz) == 0); + So(nng_getopt(s1, NNG_OPT_SNDFD, &fd, &sz) == 0); So(fd != INVALID_SOCKET); + So(nng_send(s1, "oops", 4, 0) == 0); + }) + + Convey("We cannot get a send FD for PULL", { + nng_socket s3; + int fd; + size_t sz; + So(nng_open(&s3, NNG_PROTO_PULL) == 0); + Reset({ + nng_close(s3); + }) + sz = sizeof (fd); + So(nng_getopt(s3, NNG_OPT_SNDFD, &fd, &sz) == NNG_ENOTSUP); + }) + + Convey("We cannot get a recv FD for PUSH", { + nng_socket s3; + int fd; + size_t sz; + So(nng_open(&s3, NNG_PROTO_PUSH) == 0); + Reset({ + nng_close(s3); + }) + sz = sizeof (fd); + So(nng_getopt(s3, NNG_OPT_RCVFD, &fd, &sz) == NNG_ENOTSUP); }) }) }) |
