summaryrefslogtreecommitdiff
path: root/src/transport/tls
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2019-02-16 12:40:41 -0800
committerGarrett D'Amore <garrett@damore.org>2019-02-16 19:22:27 -0800
commit60231f0600461a9593a8f876518874866df3387a (patch)
tree1a91f0b65b1ad2d5b995a3db21639f4bf7032066 /src/transport/tls
parent5cf750697624d4fd63cfe26921209d7c30e1a2d2 (diff)
downloadnng-60231f0600461a9593a8f876518874866df3387a.tar.gz
nng-60231f0600461a9593a8f876518874866df3387a.tar.bz2
nng-60231f0600461a9593a8f876518874866df3387a.zip
fixes #879 Desire NNG_OPT_TCP_BOUND_PORT
We also have made some support changes, including new APIs for printing URLs, and some improvements to the NNG_OPT_URL to make use of this new property.
Diffstat (limited to 'src/transport/tls')
-rw-r--r--src/transport/tls/tls.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c
index d68cb8b1..8b02702f 100644
--- a/src/transport/tls/tls.c
+++ b/src/transport/tls/tls.c
@@ -907,7 +907,7 @@ tlstran_ep_accept(void *arg, nni_aio *aio)
}
static int
-tlstran_ep_set_recvmaxsz(void *arg, const void *v, size_t sz, nni_opt_type t)
+tlstran_ep_set_recvmaxsz(void *arg, const void *v, size_t sz, nni_type t)
{
tlstran_ep *ep = arg;
size_t val;
@@ -921,7 +921,7 @@ tlstran_ep_set_recvmaxsz(void *arg, const void *v, size_t sz, nni_opt_type t)
}
static int
-tlstran_ep_get_recvmaxsz(void *arg, void *v, size_t *szp, nni_opt_type t)
+tlstran_ep_get_recvmaxsz(void *arg, void *v, size_t *szp, nni_type t)
{
tlstran_ep *ep = arg;
int rv;
@@ -932,30 +932,22 @@ tlstran_ep_get_recvmaxsz(void *arg, void *v, size_t *szp, nni_opt_type t)
}
static int
-tlstran_ep_get_url(void *arg, void *v, size_t *szp, nni_opt_type t)
+tlstran_ep_get_url(void *arg, void *v, size_t *szp, nni_type t)
{
- tlstran_ep * ep = arg;
- char ustr[128];
- char ipstr[48]; // max for IPv6 addresses including []
- char portstr[6]; // max for 16-bit port
- nng_sockaddr sa;
- size_t sz = sizeof(sa);
- int rv;
+ tlstran_ep *ep = arg;
+ char * s;
+ int rv;
+ int port = 0;
- if (ep->dialer != NULL) {
- return (nni_copyout_str(ep->url->u_rawurl, v, szp, t));
+ if (ep->listener != NULL) {
+ (void) nng_stream_listener_get_int(
+ ep->listener, NNG_OPT_TCP_BOUND_PORT, &port);
}
- rv = nni_stream_listener_getx(
- ep->listener, NNG_OPT_LOCADDR, &sa, &sz, NNI_TYPE_SOCKADDR);
- if (rv != 0) {
- return (rv);
+ if ((rv = nni_url_asprintf_port(&s, ep->url, port)) == 0) {
+ rv = nni_copyout_str(s, v, szp, t);
+ nni_strfree(s);
}
-
- nni_mtx_lock(&ep->mtx);
- nni_ntop(&sa, ipstr, portstr);
- nni_mtx_unlock(&ep->mtx);
- snprintf(ustr, sizeof(ustr), "tls+tcp://%s:%s", ipstr, portstr);
- return (nni_copyout_str(ustr, v, szp, t));
+ return (rv);
}
static const nni_option tlstran_pipe_opts[] = {