aboutsummaryrefslogtreecommitdiff
path: root/tests/tcpsupp.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-12-29 21:28:49 -0800
committerGarrett D'Amore <garrett@damore.org>2018-12-31 17:10:04 -0800
commita73ff5363eae228009413872b05aff758a46c5ca (patch)
treed5fa805188f915fc94c9b80d4f5cbbb96e6a4551 /tests/tcpsupp.c
parente0fff1f9c45f5486fc2e7eeb49b4462c3bb2dad4 (diff)
downloadnng-a73ff5363eae228009413872b05aff758a46c5ca.tar.gz
nng-a73ff5363eae228009413872b05aff758a46c5ca.tar.bz2
nng-a73ff5363eae228009413872b05aff758a46c5ca.zip
fixes #825 TCP public API should use generic setopt/getopt
This changes much of the internal API for TCP option handling, and includes hooks for some of this in various consumers. Note that the consumers still need to have additional work done to complete them, which will be part of providing public "raw" TLS and WebSocket APIs. We would also like to finish addressing the call sites of nni_tcp_listener_start() that assume the sockaddr is modified -- it would be superior to use the NNG_OPT_LOCADDR option. Thaat will be addressed in a follow up PR.
Diffstat (limited to 'tests/tcpsupp.c')
-rw-r--r--tests/tcpsupp.c47
1 files changed, 39 insertions, 8 deletions
diff --git a/tests/tcpsupp.c b/tests/tcpsupp.c
index 93c0ca9b..ede6a76f 100644
--- a/tests/tcpsupp.c
+++ b/tests/tcpsupp.c
@@ -90,6 +90,8 @@ TestMain("Supplemental TCP", {
nng_sockaddr sa2;
char buf1[5];
char buf2[5];
+ bool on;
+ size_t sz;
So(nng_aio_alloc(&aio1, NULL, NULL) ==
0);
@@ -101,11 +103,34 @@ TestMain("Supplemental TCP", {
nng_aio_free(aio2);
});
- So(nng_tcp_set_nodelay(c1, true) == 0);
- So(nng_tcp_set_nodelay(c2, true) == 0);
+ on = true;
+ So(nng_tcp_setopt(c1,
+ NNG_OPT_TCP_NODELAY, &on,
+ sizeof(on)) == 0);
+ So(nng_tcp_setopt(c2,
+ NNG_OPT_TCP_NODELAY, &on,
+ sizeof(on)) == 0);
+
+ So(nng_tcp_setopt(c1,
+ NNG_OPT_TCP_KEEPALIVE, &on,
+ sizeof(on)) == 0);
+
+ on = false;
+ sz = sizeof(on);
+ So(nng_tcp_getopt(c1,
+ NNG_OPT_TCP_NODELAY, &on,
+ &sz) == 0);
+ So(sz == sizeof(on));
+ So(on == true);
+
+ on = false;
+ sz = sizeof(on);
+ So(nng_tcp_getopt(c1,
+ NNG_OPT_TCP_KEEPALIVE, &on,
+ &sz) == 0);
+ So(sz == sizeof(on));
+ So(on == true);
- So(nng_tcp_set_keepalive(c1, true) ==
- 0);
// This relies on send completing for
// for just 5 bytes, and on recv doing
// the same. Technically this isn't
@@ -135,8 +160,11 @@ TestMain("Supplemental TCP", {
So(memcmp(buf1, buf2, 5) == 0);
Convey("Socket name matches", {
- So(nng_tcp_sockname(
- c2, &sa2) == 0);
+ sz = sizeof(sa2);
+ So(nng_tcp_getopt(c2,
+ NNG_OPT_LOCADDR, &sa2,
+ &sz) == 0);
+ So(sz == sizeof(sa2));
So(sa2.s_in.sa_family ==
NNG_AF_INET);
So(sa2.s_in.sa_addr == ip);
@@ -145,8 +173,11 @@ TestMain("Supplemental TCP", {
});
Convey("Peer name matches", {
- So(nng_tcp_peername(
- c1, &sa2) == 0);
+ sz = sizeof(sa2);
+ So(nng_tcp_getopt(c1,
+ NNG_OPT_REMADDR, &sa2,
+ &sz) == 0);
+ So(sz == sizeof(sa2));
So(sa2.s_in.sa_family ==
NNG_AF_INET);
So(sa2.s_in.sa_addr == ip);