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/pollfd.c | |
| 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/pollfd.c')
| -rw-r--r-- | tests/pollfd.c | 73 |
1 files changed, 66 insertions, 7 deletions
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); }) }) }) |
