From 52d37858451ad23f077294fc78b1a3f56255c32f Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 6 Oct 2017 12:26:42 -0700 Subject: Add NNG_OPT_DOMAIN and NNG_OPT_SOCKNAME support for legacy compat. The NNG_OPT_SOCKNAME option is settable, to a limit of 64 bytes. The NNG_OPT_DOMAIN is read-only, but changes to match the setting of the NNG_OPT_RAW field. New applications should not use the NNG_OPT_DOMAIN option -- it is provided solely for use with the legacy NN_DOMAIN option in the compatibility layer. --- tests/sock.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests') diff --git a/tests/sock.c b/tests/sock.c index f2afde4c..e21e687d 100644 --- a/tests/sock.c +++ b/tests/sock.c @@ -109,6 +109,48 @@ TestMain("Socket Operations", { NNG_EREADONLY); So(nng_setopt(s1, NNG_OPT_LOCADDR, "a", 1) == NNG_EREADONLY); + So(nng_setopt_int(s1, NNG_OPT_DOMAIN, 3) == + NNG_EREADONLY); + }); + + Convey("Sockname option works", { + char name[128]; // 64 is max + size_t sz; + sz = sizeof(name); + So(nng_getopt( + s1, NNG_OPT_SOCKNAME, name, &sz) == 0); + So(sz > 0 && sz < 64); + So(sz == nni_strnlen(name, 64) + 1); + So(atoi(name) == (unsigned) s1); + + So(nng_setopt( + s1, NNG_OPT_SOCKNAME, "hello", 6) == 0); + sz = sizeof(name); + So(nng_getopt( + s1, NNG_OPT_SOCKNAME, name, &sz) == 0); + So(sz == 6); + So(strcmp(name, "hello") == 0); + + memset(name, 'A', 64); + name[64] = '\0'; + So(nng_setopt(s1, NNG_OPT_SOCKNAME, name, + strlen(name)) == NNG_EINVAL); + + So(nng_getopt( + s1, NNG_OPT_SOCKNAME, name, &sz) == 0); + So(sz == 6); + So(strcmp(name, "hello") == 0); + }); + + Convey("Domain option works", { + int dom; + So(nng_getopt_int(s1, NNG_OPT_DOMAIN, &dom) == + 0); + So(dom == 1); // NN_AF_SP + So(nng_setopt_int(s1, NNG_OPT_RAW, 1) == 0); + So(nng_getopt_int(s1, NNG_OPT_DOMAIN, &dom) == + 0); + So(dom == 2); // NN_AF_SP_RAW }); Convey("URL option works", { -- cgit v1.2.3-70-g09d2