diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-12-29 21:28:49 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-12-31 17:10:04 -0800 |
| commit | a73ff5363eae228009413872b05aff758a46c5ca (patch) | |
| tree | d5fa805188f915fc94c9b80d4f5cbbb96e6a4551 /tests | |
| parent | e0fff1f9c45f5486fc2e7eeb49b4462c3bb2dad4 (diff) | |
| download | nng-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')
| -rw-r--r-- | tests/tcp.c | 6 | ||||
| -rw-r--r-- | tests/tcpsupp.c | 47 |
2 files changed, 45 insertions, 8 deletions
diff --git a/tests/tcp.c b/tests/tcp.c index 53372fa5..8975da33 100644 --- a/tests/tcp.c +++ b/tests/tcp.c @@ -1,6 +1,7 @@ // // Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> +// Copyright 2018 Devolutions <info@devolutions.net> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -93,6 +94,7 @@ TestMain("TCP Transport", { Convey("We can bind to port zero", { nng_socket s1; nng_socket s2; + nng_sockaddr sa; nng_listener l; char * addr; @@ -105,6 +107,10 @@ TestMain("TCP Transport", { So(nng_listen(s1, "tcp://127.0.0.1:0", &l, 0) == 0); So(nng_listener_getopt_string(l, NNG_OPT_URL, &addr) == 0); So(memcmp(addr, "tcp://", 6) == 0); + So(nng_listener_getopt_sockaddr(l, NNG_OPT_LOCADDR, &sa) == 0); + So(sa.s_in.sa_family == NNG_AF_INET); + So(sa.s_in.sa_port != 0); + So(sa.s_in.sa_addr = htonl(0x7f000001)); So(nng_dial(s2, addr, NULL, 0) == 0); nng_strfree(addr); }); 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); |
