aboutsummaryrefslogtreecommitdiff
path: root/src/core/endpt.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-01-22 14:05:10 -0800
committerGarrett D'Amore <garrett@damore.org>2018-01-22 17:11:58 -0800
commit3d075fad7496ec126c5087d1c36ab7a4af73ce16 (patch)
treec5b5d6fe44eaa2996310683b5080de87160b9b41 /src/core/endpt.c
parent5b1a3af7be4ae712868ae84b9a7d5a974d272b16 (diff)
downloadnng-3d075fad7496ec126c5087d1c36ab7a4af73ce16.tar.gz
nng-3d075fad7496ec126c5087d1c36ab7a4af73ce16.tar.bz2
nng-3d075fad7496ec126c5087d1c36ab7a4af73ce16.zip
fixes #219 transports should take URL structure instead of string address
This eliminates a bunch of redundant URL parsing, using the common URL logic we already have in place. While here I fixed a problem with the TLS and WSS test suites that was failing on older Ubuntu -- apparently older versions of mbedTLS were unhappy if selecting OPTIONAL verification without a validate certificate chain.
Diffstat (limited to 'src/core/endpt.c')
-rw-r--r--src/core/endpt.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/core/endpt.c b/src/core/endpt.c
index 57e4bc62..cfabcc87 100644
--- a/src/core/endpt.c
+++ b/src/core/endpt.c
@@ -21,7 +21,7 @@ struct nni_ep {
uint64_t ep_id; // endpoint id
nni_list_node ep_node; // per socket list
nni_sock * ep_sock;
- char ep_url[NNG_MAXADDRLEN];
+ nni_url * ep_url;
int ep_mode;
int ep_started;
int ep_closed; // full shutdown
@@ -82,12 +82,6 @@ nni_ep_id(nni_ep *ep)
return ((uint32_t) ep->ep_id);
}
-const char *
-nni_ep_url(nni_ep *ep)
-{
- return (ep->ep_url);
-}
-
static void
nni_ep_destroy(nni_ep *ep)
{
@@ -119,26 +113,31 @@ nni_ep_destroy(nni_ep *ep)
nni_mtx_unlock(&ep->ep_mtx);
nni_cv_fini(&ep->ep_cv);
nni_mtx_fini(&ep->ep_mtx);
+ nni_url_free(ep->ep_url);
NNI_FREE_STRUCT(ep);
}
static int
-nni_ep_create(nni_ep **epp, nni_sock *s, const char *url, int mode)
+nni_ep_create(nni_ep **epp, nni_sock *s, const char *urlstr, int mode)
{
nni_tran *tran;
nni_ep * ep;
int rv;
+ nni_url * url;
+ if ((rv = nni_url_parse(&url, urlstr)) != 0) {
+ return (rv);
+ }
if ((tran = nni_tran_find(url)) == NULL) {
+ nni_url_free(url);
return (NNG_ENOTSUP);
}
- if (strlen(url) >= NNG_MAXADDRLEN) {
- return (NNG_EINVAL);
- }
if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) {
+ nni_url_free(url);
return (NNG_ENOMEM);
}
+ ep->ep_url = url;
ep->ep_closed = 0;
ep->ep_started = 0;
ep->ep_data = NULL;
@@ -152,8 +151,6 @@ nni_ep_create(nni_ep **epp, nni_sock *s, const char *url, int mode)
// dereference on hot paths.
ep->ep_ops = *tran->tran_ep;
- (void) nni_strlcpy(ep->ep_url, url, sizeof(ep->ep_url));
-
NNI_LIST_NODE_INIT(&ep->ep_node);
nni_pipe_ep_list_init(&ep->ep_pipes);
@@ -177,15 +174,15 @@ nni_ep_create(nni_ep **epp, nni_sock *s, const char *url, int mode)
}
int
-nni_ep_create_dialer(nni_ep **epp, nni_sock *s, const char *url)
+nni_ep_create_dialer(nni_ep **epp, nni_sock *s, const char *urlstr)
{
- return (nni_ep_create(epp, s, url, NNI_EP_MODE_DIAL));
+ return (nni_ep_create(epp, s, urlstr, NNI_EP_MODE_DIAL));
}
int
-nni_ep_create_listener(nni_ep **epp, nni_sock *s, const char *url)
+nni_ep_create_listener(nni_ep **epp, nni_sock *s, const char *urlstr)
{
- return (nni_ep_create(epp, s, url, NNI_EP_MODE_LISTEN));
+ return (nni_ep_create(epp, s, urlstr, NNI_EP_MODE_LISTEN));
}
int
@@ -622,7 +619,7 @@ nni_ep_getopt(nni_ep *ep, const char *name, void *valp, size_t *szp)
nni_tran_ep_option *eo;
if (strcmp(name, NNG_OPT_URL) == 0) {
- return (nni_getopt_str(ep->ep_url, valp, szp));
+ return (nni_getopt_str(ep->ep_url->u_rawurl, valp, szp));
}
for (eo = ep->ep_ops.ep_options; eo && eo->eo_name; eo++) {