Skip to content

Commit

Permalink
Select transport using raw URL string.
Browse files Browse the repository at this point in the history
This is done so that we can provide transport specific logic
for URL parsing later (we're going to want this for ZeroTier
for example.)
  • Loading branch information
gdamore committed Nov 23, 2024
1 parent 5836e6b commit e6696ed
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/core/dialer.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,16 @@ nni_dialer_create(nni_dialer **dp, nni_sock *s, const char *url_str)
if ((d = NNI_ALLOC_STRUCT(d)) == NULL) {
return (NNG_ENOMEM);

Check warning on line 220 in src/core/dialer.c

View check run for this annotation

Codecov / codecov/patch

src/core/dialer.c#L220

Added line #L220 was not covered by tests
}
if ((rv = nni_url_parse_inline(&d->d_url, url_str)) != 0) {
NNI_FREE_STRUCT(d);
return (rv);
}
if (((tran = nni_sp_tran_find(&d->d_url)) == NULL) ||
if (((tran = nni_sp_tran_find(url_str)) == NULL) ||
(tran->tran_dialer == NULL)) {
nni_url_fini(&d->d_url);
NNI_FREE_STRUCT(d);
return (NNG_ENOTSUP);
}
if ((rv = nni_url_parse_inline(&d->d_url, url_str)) != 0) {
NNI_FREE_STRUCT(d);
return (rv);
}
d->d_closed = false;
d->d_data = NULL;
d->d_ref = 1;
Expand Down
11 changes: 5 additions & 6 deletions src/core/listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,15 @@ nni_listener_create(nni_listener **lp, nni_sock *s, const char *url_str)
if ((l = NNI_ALLOC_STRUCT(l)) == NULL) {
return (NNG_ENOMEM);

Check warning on line 208 in src/core/listener.c

View check run for this annotation

Codecov / codecov/patch

src/core/listener.c#L208

Added line #L208 was not covered by tests
}
if ((rv = nni_url_parse_inline(&l->l_url, url_str)) != 0) {
nni_url_fini(&l->l_url);
if (((tran = nni_sp_tran_find(url_str)) == NULL) ||
(tran->tran_listener == NULL)) {
NNI_FREE_STRUCT(l);
return (rv);
return (NNG_ENOTSUP);
}
if (((tran = nni_sp_tran_find(&l->l_url)) == NULL) ||
(tran->tran_listener == NULL)) {
if ((rv = nni_url_parse_inline(&l->l_url, url_str)) != 0) {
nni_url_fini(&l->l_url);
NNI_FREE_STRUCT(l);
return (NNG_ENOTSUP);
return (rv);

Check warning on line 218 in src/core/listener.c

View check run for this annotation

Codecov / codecov/patch

src/core/listener.c#L216-L218

Added lines #L216 - L218 were not covered by tests
}
l->l_closed = false;
l->l_data = NULL;
Expand Down
6 changes: 4 additions & 2 deletions src/sp/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ nni_sp_tran_register(nni_sp_tran *tran)
}

nni_sp_tran *
nni_sp_tran_find(nng_url *url)
nni_sp_tran_find(const char *url)
{
// address is of the form "<scheme>://blah..."
nni_sp_tran *t;

nni_rwlock_rdlock(&sp_tran_lk);
NNI_LIST_FOREACH (&sp_tran_list, t) {
if (strcmp(url->u_scheme, t->tran_scheme) == 0) {
size_t len = strlen(t->tran_scheme);
if ((strncmp(url, t->tran_scheme, len) == 0) &&
(strncmp(url + len, "://", 3) == 0)) {
nni_rwlock_unlock(&sp_tran_lk);
return (t);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sp/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ struct nni_sp_tran {

// These APIs are used by the framework internally, and not for use by
// transport implementations.
extern nni_sp_tran *nni_sp_tran_find(nng_url *);
extern nni_sp_tran *nni_sp_tran_find(const char *);
extern void nni_sp_tran_sys_init(void);
extern void nni_sp_tran_sys_fini(void);
extern void nni_sp_tran_register(nni_sp_tran *);
Expand Down
4 changes: 2 additions & 2 deletions tests/trantest.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ trantest_init(trantest *tt, const char *addr)
So(nng_rep_open(&tt->repsock) == 0);

nng_url *url;
So(nng_url_parse(&url, tt->addr) == 0);
tt->tran = nni_sp_tran_find(url);
tt->tran = nni_sp_tran_find(addr);
So(tt->tran != NULL);
So(nng_url_parse(&url, tt->addr) == 0);
nng_url_free(url);
}

Expand Down

0 comments on commit e6696ed

Please sign in to comment.