diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-09-25 12:49:10 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-09-27 14:38:12 -0700 |
| commit | 64db0f085be0c9efc6dca8d9e72d3e5a47cb792e (patch) | |
| tree | 475520498d8ebe9e47e9785d8f9d209c87582400 /tests/pollfd.c | |
| parent | 86a96e5bf1b207a8b1aa925e1d9f73ce834505b8 (diff) | |
| download | nng-64db0f085be0c9efc6dca8d9e72d3e5a47cb792e.tar.gz nng-64db0f085be0c9efc6dca8d9e72d3e5a47cb792e.tar.bz2 nng-64db0f085be0c9efc6dca8d9e72d3e5a47cb792e.zip | |
Refactor option handling APIs.
This makes the APIs use string keys, and largely eliminates the use of
integer option IDs altogether. The underlying registration for options
is also now a bit richer, letting protcols and transports declare the
actual options they use, rather than calling down into each entry point
carte blanche and relying on ENOTSUP.
This code may not be as fast as the integers was, but it is more intuitive,
easier to extend, and is not on any hot code paths. (If you're diddling
options on a hot code path you're doing something wrong.)
Diffstat (limited to 'tests/pollfd.c')
| -rw-r--r-- | tests/pollfd.c | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/tests/pollfd.c b/tests/pollfd.c index 6cf712f1..e5130f57 100644 --- a/tests/pollfd.c +++ b/tests/pollfd.c @@ -34,24 +34,6 @@ TestMain("Poll FDs", { - Convey("Option values work", { - int opt; - const char *name; - - opt = nng_option_lookup(nng_opt_recvfd); - So(opt > 0); - So(opt == nng_optid_recvfd); - name = nng_option_name(opt); - So(name != NULL); - So(strcmp(name, nng_opt_recvfd) == 0); - opt = nng_option_lookup(nng_opt_sendfd); - So(opt > 0); - So(opt == nng_optid_sendfd); - name = nng_option_name(opt); - So(name != NULL); - So(strcmp(name, nng_opt_sendfd) == 0); - }); - Convey("Given a connected pair of sockets", { nng_socket s1; nng_socket s2; @@ -73,14 +55,14 @@ TestMain("Poll FDs", { size_t sz; sz = sizeof(fd); - So(nng_getopt(s1, nng_optid_recvfd, &fd, &sz) == 0); + So(nng_getopt(s1, NNG_OPT_RECVFD, &fd, &sz) == 0); So(fd != INVALID_SOCKET); Convey("And it is always the same fd", { int fd2; sz = sizeof(fd2); - So(nng_getopt( - s1, nng_optid_recvfd, &fd2, &sz) == 0); + So(nng_getopt(s1, NNG_OPT_RECVFD, &fd2, &sz) == + 0); So(fd2 == fd); }); @@ -111,7 +93,7 @@ TestMain("Poll FDs", { size_t sz; sz = sizeof(fd); - So(nng_getopt(s1, nng_optid_sendfd, &fd, &sz) == 0); + So(nng_getopt(s1, NNG_OPT_SENDFD, &fd, &sz) == 0); So(fd != INVALID_SOCKET); So(nng_send(s1, "oops", 4, 0) == 0); }); @@ -120,10 +102,10 @@ TestMain("Poll FDs", { int fd; size_t sz; sz = 1; - So(nng_getopt(s1, nng_optid_recvfd, &fd, &sz) == + So(nng_getopt(s1, NNG_OPT_RECVFD, &fd, &sz) == NNG_EINVAL); sz = 128; - So(nng_getopt(s1, nng_optid_recvfd, &fd, &sz) == 0); + So(nng_getopt(s1, NNG_OPT_RECVFD, &fd, &sz) == 0); So(sz == sizeof(fd)); }); Convey("We cannot get a send FD for PULL", { @@ -133,7 +115,7 @@ TestMain("Poll FDs", { So(nng_pull_open(&s3) == 0); Reset({ nng_close(s3); }); sz = sizeof(fd); - So(nng_getopt(s3, nng_optid_sendfd, &fd, &sz) == + So(nng_getopt(s3, NNG_OPT_SENDFD, &fd, &sz) == NNG_ENOTSUP); }); @@ -144,7 +126,7 @@ TestMain("Poll FDs", { So(nng_push_open(&s3) == 0); Reset({ nng_close(s3); }); sz = sizeof(fd); - So(nng_getopt(s3, nng_optid_recvfd, &fd, &sz) == + So(nng_getopt(s3, NNG_OPT_RECVFD, &fd, &sz) == NNG_ENOTSUP); }); }); |
