aboutsummaryrefslogtreecommitdiff
path: root/tests/tcp.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-08-19 08:07:02 -0700
committerGarrett D'Amore <garrett@damore.org>2018-08-27 08:00:23 -0700
commit83b7a9afec7b3659974c614cea69fa3abb904d24 (patch)
tree7277bda8deb32c91614f236fb942a4c6cfbbe55b /tests/tcp.c
parent1c3350f6f4a738815c39a67dc0ba1a953a1b9f03 (diff)
downloadnng-83b7a9afec7b3659974c614cea69fa3abb904d24.tar.gz
nng-83b7a9afec7b3659974c614cea69fa3abb904d24.tar.bz2
nng-83b7a9afec7b3659974c614cea69fa3abb904d24.zip
fixes #608 Add TCP support to specify local network interface
This also fixes a leaked TCP connection on a failure path, which we noticed while working this change.
Diffstat (limited to 'tests/tcp.c')
-rw-r--r--tests/tcp.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/tcp.c b/tests/tcp.c
index 0018fce7..d13cc83d 100644
--- a/tests/tcp.c
+++ b/tests/tcp.c
@@ -59,7 +59,6 @@ check_props_v4(nng_msg *msg)
}
TestMain("TCP Transport", {
-
trantest_test_extended("tcp://127.0.0.1:%u", check_props_v4);
Convey("We cannot connect to wild cards", {
@@ -109,6 +108,42 @@ TestMain("TCP Transport", {
nng_strfree(addr);
});
+ Convey("We can use local interface to connet", {
+ nng_socket s1;
+ nng_socket s2;
+ char addr[NNG_MAXADDRLEN];
+
+ So(nng_pair_open(&s1) == 0);
+ So(nng_pair_open(&s2) == 0);
+ Reset({
+ nng_close(s2);
+ nng_close(s1);
+ });
+ trantest_next_address(addr, "tcp://127.0.0.1:%u");
+ So(nng_listen(s1, addr, NULL, 0) == 0);
+ // reset port back one
+ trantest_prev_address(addr, "tcp://127.0.0.1;127.0.0.1:%u");
+ So(nng_dial(s2, addr, NULL, 0) == 0);
+ });
+
+ Convey("Botched local interfaces fail resonably", {
+ nng_socket s1;
+
+ So(nng_pair_open(&s1) == 0);
+ Reset({ nng_close(s1); });
+ So(nng_dial(s1, "tcp://1x.2;127.0.0.1:80", NULL, 0) ==
+ NNG_EADDRINVAL);
+ });
+
+ Convey("Can't specify address that isn't ours", {
+ nng_socket s1;
+
+ So(nng_pair_open(&s1) == 0);
+ Reset({ nng_close(s1); });
+ So(nng_dial(s1, "tcp://8.8.8.8;127.0.0.1:80", NULL, 0) ==
+ NNG_EADDRINVAL);
+ });
+
Convey("Malformed TCP addresses do not panic", {
nng_socket s1;