aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/options.c6
-rw-r--r--tests/pollfd.c18
-rw-r--r--tests/sock.c97
3 files changed, 114 insertions, 7 deletions
diff --git a/src/core/options.c b/src/core/options.c
index 6d4afdb4..170e7407 100644
--- a/src/core/options.c
+++ b/src/core/options.c
@@ -1,5 +1,6 @@
//
-// Copyright 2016 Garrett D'Amore <garrett@damore.org>
+// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2017 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -191,7 +192,8 @@ nni_getopt_fd(nni_sock *s, nni_notifyfd *fd, int mask, void *val, size_t *szp)
return (NNG_ENOMEM);
}
- *szp = sizeof(int);
+ fd->sn_init = 1;
+ *szp = sizeof(int);
memcpy(val, &fd->sn_rfd, sizeof(int));
return (0);
}
diff --git a/tests/pollfd.c b/tests/pollfd.c
index 09ce43cc..05ed2939 100644
--- a/tests/pollfd.c
+++ b/tests/pollfd.c
@@ -56,6 +56,14 @@ TestMain("Poll FDs",
So(nng_getopt(s1, NNG_OPT_RCVFD, &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_OPT_RCVFD, &fd2, &sz) ==
+ 0);
+ So(fd2 == fd);
+ });
+
Convey("And they start non pollable", {
struct pollfd pfd;
pfd.fd = fd;
@@ -88,6 +96,16 @@ TestMain("Poll FDs",
So(nng_send(s1, "oops", 4, 0) == 0);
});
+ Convey("Must have a big enough size", {
+ int fd;
+ size_t sz;
+ sz = 1;
+ So(nng_getopt(s1, NNG_OPT_RCVFD, &fd, &sz) ==
+ NNG_EINVAL);
+ sz = 128;
+ So(nng_getopt(s1, NNG_OPT_RCVFD, &fd, &sz) == 0);
+ So(sz == sizeof(fd));
+ });
Convey("We cannot get a send FD for PULL", {
nng_socket s3;
int fd;
diff --git a/tests/sock.c b/tests/sock.c
index 27599e47..bec62817 100644
--- a/tests/sock.c
+++ b/tests/sock.c
@@ -94,14 +94,98 @@ Main({
So(rv == 0);
So(sz == sizeof(check));
So(check == 0);
- }) Convey("Correct size is copied", {
+ });
+ Convey("Correct size is copied", {
sz = sizeof(check);
rv = nng_getopt(sock, NNG_OPT_SNDTIMEO,
&check, &sz);
So(rv == 0);
So(sz == sizeof(check));
So(check == 1234);
- })
+ });
+
+ Convey("Short size buf is not copied", {
+ int len = 5;
+ sz = 0;
+ So(nng_getopt(sock, NNG_OPT_RCVBUF,
+ &len, &sz) == 0);
+ So(len == 5);
+ });
+
+ Convey("Insane buffer size fails", {
+ int len = 1024 * 1024;
+ sz = sizeof(len);
+ So(nng_setopt(sock, NNG_OPT_RCVBUF,
+ &len, sz) == NNG_EINVAL);
+ });
+
+ Convey("Negative timeout fails", {
+ when = -5;
+ sz = sizeof(when);
+ So(nng_setopt(sock, NNG_OPT_RCVTIMEO,
+ &when, sz) == NNG_EINVAL);
+ });
+
+ Convey("Short timeout fails", {
+ when = 0;
+ sz = sizeof(when) - 1;
+ So(nng_setopt(sock, NNG_OPT_RCVTIMEO,
+ &when, sz) == NNG_EINVAL);
+ });
+
+ Convey("Bogus raw fails", {
+ int raw = 42;
+ sz = sizeof(raw);
+
+ raw = 42;
+ So(nng_setopt(sock, NNG_OPT_RAW, &raw,
+ sz) == NNG_EINVAL);
+ raw = -42;
+ So(nng_setopt(sock, NNG_OPT_RAW, &raw,
+ sz) == NNG_EINVAL);
+
+ raw = 0;
+ So(nng_setopt(sock, NNG_OPT_RAW, &raw,
+ sz) == 0);
+ });
+
+ Convey("Unsupported options fail", {
+ char *crap = "crap";
+ So(nng_setopt(sock, NNG_OPT_SUBSCRIBE,
+ crap,
+ strlen(crap)) == NNG_ENOTSUP);
+ });
+
+ Convey("Bogus sizes fail", {
+ size_t rmax;
+ rmax = 6550;
+ So(nng_setopt(sock, NNG_OPT_RCVMAXSZ,
+ &rmax, sizeof(rmax)) == 0);
+ rmax = 0;
+ sz = sizeof(rmax);
+ So(nng_getopt(sock, NNG_OPT_RCVMAXSZ,
+ &rmax, &sz) == 0);
+ So(rmax == 6550);
+
+ rmax = 102400;
+ So(nng_setopt(sock, NNG_OPT_RCVMAXSZ,
+ &rmax, 1) == NNG_EINVAL);
+ So(nng_getopt(sock, NNG_OPT_RCVMAXSZ,
+ &rmax, &sz) == 0);
+ So(rmax == 6550);
+
+ if (sizeof(size_t) == 8) {
+ rmax = 0x1000000000000ull;
+ So(nng_setopt(sock,
+ NNG_OPT_RCVMAXSZ, &rmax,
+ sizeof(rmax)) ==
+ NNG_EINVAL);
+ So(nng_getopt(sock,
+ NNG_OPT_RCVMAXSZ, &rmax,
+ &sz) == 0);
+ So(rmax == 6550);
+ }
+ });
});
Convey("Bogus URLs not supported", {
@@ -157,10 +241,13 @@ Main({
So(nng_setopt(sock, NNG_OPT_RCVBUF, &len,
sizeof(len)) == 0);
- So(nng_setopt(sock, NNG_OPT_SNDBUF, &len,
- sizeof(len)) == 0);
+ sz = sizeof(len);
+ So(nng_getopt(
+ sock, NNG_OPT_RCVBUF, &len, &sz) == 0);
+ So(len == 1);
+ sz = 0;
- So(nng_setopt(sock2, NNG_OPT_RCVBUF, &len,
+ So(nng_setopt(sock, NNG_OPT_SNDBUF, &len,
sizeof(len)) == 0);
So(nng_setopt(sock2, NNG_OPT_SNDBUF, &len,
sizeof(len)) == 0);