diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-09-25 12:49:10 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-09-27 14:38:12 -0700 |
| commit | 64db0f085be0c9efc6dca8d9e72d3e5a47cb792e (patch) | |
| tree | 475520498d8ebe9e47e9785d8f9d209c87582400 /src/transport/inproc | |
| parent | 86a96e5bf1b207a8b1aa925e1d9f73ce834505b8 (diff) | |
| download | nng-64db0f085be0c9efc6dca8d9e72d3e5a47cb792e.tar.gz nng-64db0f085be0c9efc6dca8d9e72d3e5a47cb792e.tar.bz2 nng-64db0f085be0c9efc6dca8d9e72d3e5a47cb792e.zip | |
Refactor option handling APIs.
This makes the APIs use string keys, and largely eliminates the use of
integer option IDs altogether. The underlying registration for options
is also now a bit richer, letting protcols and transports declare the
actual options they use, rather than calling down into each entry point
carte blanche and relying on ENOTSUP.
This code may not be as fast as the integers was, but it is more intuitive,
easier to extend, and is not on any hot code paths. (If you're diddling
options on a hot code path you're doing something wrong.)
Diffstat (limited to 'src/transport/inproc')
| -rw-r--r-- | src/transport/inproc/inproc.c | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c index e3cc5143..3f013f92 100644 --- a/src/transport/inproc/inproc.c +++ b/src/transport/inproc/inproc.c @@ -177,25 +177,15 @@ nni_inproc_pipe_peer(void *arg) } static int -nni_inproc_pipe_getopt(void *arg, int option, void *buf, size_t *szp) +nni_inproc_pipe_get_addr(void *arg, void *buf, size_t *szp) { -#if 0 - nni_inproc_pipe *pipe = arg; + nni_inproc_pipe *p = arg; + nni_sockaddr sa; - switch (option) { - case NNG_OPT_LOCALADDR: - case NNG_OPT_REMOTEADDR: - len = strlen(pipe->addr) + 1; - if (len > *szp) { - (void) memcpy(buf, pipe->addr, *szp); - } else { - (void) memcpy(buf, pipe->addr, len); - } - *szp = len; - return (0); - } -#endif - return (NNG_ENOTSUP); + sa.s_un.s_inproc.sa_family = NNG_AF_INPROC; + nni_strlcpy(sa.s_un.s_inproc.sa_path, p->addr, + sizeof(sa.s_un.s_inproc.sa_path)); + return (nni_getopt_sockaddr(&sa, buf, szp)); } static int @@ -442,13 +432,25 @@ nni_inproc_ep_accept(void *arg, nni_aio *aio) nni_mtx_unlock(&nni_inproc.mx); } +static nni_tran_pipe_option nni_inproc_pipe_options[] = { + { NNG_OPT_LOCADDR, nni_inproc_pipe_get_addr }, + { NNG_OPT_REMADDR, nni_inproc_pipe_get_addr }, + // terminate list + { NULL, NULL }, +}; + static nni_tran_pipe nni_inproc_pipe_ops = { - .p_fini = nni_inproc_pipe_fini, - .p_send = nni_inproc_pipe_send, - .p_recv = nni_inproc_pipe_recv, - .p_close = nni_inproc_pipe_close, - .p_peer = nni_inproc_pipe_peer, - .p_getopt = nni_inproc_pipe_getopt, + .p_fini = nni_inproc_pipe_fini, + .p_send = nni_inproc_pipe_send, + .p_recv = nni_inproc_pipe_recv, + .p_close = nni_inproc_pipe_close, + .p_peer = nni_inproc_pipe_peer, + .p_options = nni_inproc_pipe_options, +}; + +static nni_tran_ep_option nni_inproc_ep_options[] = { + // terminate list + { NULL, NULL, NULL }, }; static nni_tran_ep nni_inproc_ep_ops = { @@ -458,8 +460,7 @@ static nni_tran_ep nni_inproc_ep_ops = { .ep_bind = nni_inproc_ep_bind, .ep_accept = nni_inproc_ep_accept, .ep_close = nni_inproc_ep_close, - .ep_setopt = NULL, - .ep_getopt = NULL, + .ep_options = nni_inproc_ep_options, }; // This is the inproc transport linkage, and should be the only global |
