diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-06-12 20:05:34 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-06-13 18:01:52 -0700 |
| commit | da2aac4a6eb10af88e3938068e24c58aea1832b1 (patch) | |
| tree | fb0676be5426ed1510945b7e7fe3d09eb45333a7 /src/protocol/survey0 | |
| parent | 61ffae5e3649897776c26799ccaaa35d578ba816 (diff) | |
| download | nng-da2aac4a6eb10af88e3938068e24c58aea1832b1.tar.gz nng-da2aac4a6eb10af88e3938068e24c58aea1832b1.tar.bz2 nng-da2aac4a6eb10af88e3938068e24c58aea1832b1.zip | |
fixes #540 nni_ep_opttype serves no purpose
fixes #538 setopt should have an explicit chkopt routine
fixes #537 Internal TCP API needs better name separation
fixes #524 Option types should be "typed"
This is a rework of the option management code, to make it both clearer
and to prepare for further work to break up endpoints. This reduces
a certain amount of dead or redundant code, and actually saves cycles
when setting options, as some loops were not terminated that should have
been.
Diffstat (limited to 'src/protocol/survey0')
| -rw-r--r-- | src/protocol/survey0/respond.c | 44 | ||||
| -rw-r--r-- | src/protocol/survey0/survey.c | 79 | ||||
| -rw-r--r-- | src/protocol/survey0/xrespond.c | 20 | ||||
| -rw-r--r-- | src/protocol/survey0/xsurvey.c | 20 |
4 files changed, 81 insertions, 82 deletions
diff --git a/src/protocol/survey0/respond.c b/src/protocol/survey0/respond.c index 569fd4ea..db18a4e8 100644 --- a/src/protocol/survey0/respond.c +++ b/src/protocol/survey0/respond.c @@ -587,21 +587,21 @@ drop: } static int -resp0_sock_setopt_maxttl(void *arg, const void *buf, size_t sz, int typ) +resp0_sock_set_maxttl(void *arg, const void *buf, size_t sz, nni_opt_type t) { resp0_sock *s = arg; - return (nni_copyin_int(&s->ttl, buf, sz, 1, 255, typ)); + return (nni_copyin_int(&s->ttl, buf, sz, 1, 255, t)); } static int -resp0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp, int typ) +resp0_sock_get_maxttl(void *arg, void *buf, size_t *szp, nni_opt_type t) { resp0_sock *s = arg; - return (nni_copyout_int(s->ttl, buf, szp, typ)); + return (nni_copyout_int(s->ttl, buf, szp, t)); } static int -resp0_sock_getopt_sendfd(void *arg, void *buf, size_t *szp, int typ) +resp0_sock_get_sendfd(void *arg, void *buf, size_t *szp, nni_opt_type t) { resp0_sock *s = arg; int rv; @@ -610,11 +610,11 @@ resp0_sock_getopt_sendfd(void *arg, void *buf, size_t *szp, int typ) if ((rv = nni_pollable_getfd(s->sendable, &fd)) != 0) { return (rv); } - return (nni_copyout_int(fd, buf, szp, typ)); + return (nni_copyout_int(fd, buf, szp, t)); } static int -resp0_sock_getopt_recvfd(void *arg, void *buf, size_t *szp, int typ) +resp0_sock_get_recvfd(void *arg, void *buf, size_t *szp, nni_opt_type t) { resp0_sock *s = arg; int rv; @@ -623,7 +623,7 @@ resp0_sock_getopt_recvfd(void *arg, void *buf, size_t *szp, int typ) if ((rv = nni_pollable_getfd(s->recvable, &fd)) != 0) { return (rv); } - return (nni_copyout_int(fd, buf, szp, typ)); + return (nni_copyout_int(fd, buf, szp, t)); } static void @@ -657,28 +657,28 @@ static nni_proto_ctx_ops resp0_ctx_ops = { .ctx_recv = resp0_ctx_recv, }; -static nni_proto_sock_option resp0_sock_options[] = { +static nni_proto_option resp0_sock_options[] = { { - .pso_name = NNG_OPT_MAXTTL, - .pso_type = NNI_TYPE_INT32, - .pso_getopt = resp0_sock_getopt_maxttl, - .pso_setopt = resp0_sock_setopt_maxttl, + .o_name = NNG_OPT_MAXTTL, + .o_type = NNI_TYPE_INT32, + .o_get = resp0_sock_get_maxttl, + .o_set = resp0_sock_set_maxttl, }, { - .pso_name = NNG_OPT_RECVFD, - .pso_type = NNI_TYPE_INT32, - .pso_getopt = resp0_sock_getopt_recvfd, - .pso_setopt = NULL, + .o_name = NNG_OPT_RECVFD, + .o_type = NNI_TYPE_INT32, + .o_get = resp0_sock_get_recvfd, + .o_set = NULL, }, { - .pso_name = NNG_OPT_SENDFD, - .pso_type = NNI_TYPE_INT32, - .pso_getopt = resp0_sock_getopt_sendfd, - .pso_setopt = NULL, + .o_name = NNG_OPT_SENDFD, + .o_type = NNI_TYPE_INT32, + .o_get = resp0_sock_get_sendfd, + .o_set = NULL, }, // terminate list { - .pso_name = NULL, + .o_name = NULL, }, }; diff --git a/src/protocol/survey0/survey.c b/src/protocol/survey0/survey.c index 24a35003..42d88f13 100644 --- a/src/protocol/survey0/survey.c +++ b/src/protocol/survey0/survey.c @@ -449,49 +449,50 @@ surv0_pipe_recv_cb(void *arg) } static int -surv0_ctx_setopt_surveytime(void *arg, const void *buf, size_t sz, int typ) +surv0_ctx_set_surveytime(void *arg, const void *buf, size_t sz, nni_opt_type t) { surv0_ctx *ctx = arg; - return (nni_copyin_ms(&ctx->survtime, buf, sz, typ)); + return (nni_copyin_ms(&ctx->survtime, buf, sz, t)); } static int -surv0_ctx_getopt_surveytime(void *arg, void *buf, size_t *szp, int typ) +surv0_ctx_get_surveytime(void *arg, void *buf, size_t *szp, nni_opt_type t) { surv0_ctx *ctx = arg; - return (nni_copyout_ms(ctx->survtime, buf, szp, typ)); + return (nni_copyout_ms(ctx->survtime, buf, szp, t)); } static int -surv0_sock_setopt_maxttl(void *arg, const void *buf, size_t sz, int typ) +surv0_sock_set_maxttl(void *arg, const void *buf, size_t sz, nni_opt_type t) { surv0_sock *s = arg; - return (nni_copyin_int(&s->ttl, buf, sz, 1, 255, typ)); + return (nni_copyin_int(&s->ttl, buf, sz, 1, 255, t)); } static int -surv0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp, int typ) +surv0_sock_get_maxttl(void *arg, void *buf, size_t *szp, nni_opt_type t) { surv0_sock *s = arg; - return (nni_copyout_int(s->ttl, buf, szp, typ)); + return (nni_copyout_int(s->ttl, buf, szp, t)); } static int -surv0_sock_setopt_surveytime(void *arg, const void *buf, size_t sz, int typ) +surv0_sock_set_surveytime( + void *arg, const void *buf, size_t sz, nni_opt_type t) { surv0_sock *s = arg; - return (surv0_ctx_setopt_surveytime(s->ctx, buf, sz, typ)); + return (surv0_ctx_set_surveytime(s->ctx, buf, sz, t)); } static int -surv0_sock_getopt_surveytime(void *arg, void *buf, size_t *szp, int typ) +surv0_sock_get_surveytime(void *arg, void *buf, size_t *szp, nni_opt_type t) { surv0_sock *s = arg; - return (surv0_ctx_getopt_surveytime(s->ctx, buf, szp, typ)); + return (surv0_ctx_get_surveytime(s->ctx, buf, szp, t)); } static int -surv0_sock_getopt_sendfd(void *arg, void *buf, size_t *szp, int typ) +surv0_sock_get_sendfd(void *arg, void *buf, size_t *szp, nni_opt_type t) { surv0_sock *sock = arg; int rv; @@ -510,11 +511,11 @@ surv0_sock_getopt_sendfd(void *arg, void *buf, size_t *szp, int typ) if ((rv = nni_pollable_getfd(sock->sendable, &fd)) != 0) { return (rv); } - return (nni_copyout_int(fd, buf, szp, typ)); + return (nni_copyout_int(fd, buf, szp, t)); } static int -surv0_sock_getopt_recvfd(void *arg, void *buf, size_t *szp, int typ) +surv0_sock_get_recvfd(void *arg, void *buf, size_t *szp, nni_opt_type t) { surv0_sock * sock = arg; nni_pollable *recvable; @@ -525,7 +526,7 @@ surv0_sock_getopt_recvfd(void *arg, void *buf, size_t *szp, int typ) ((rv = nni_pollable_getfd(recvable, &fd)) != 0)) { return (rv); } - return (nni_copyout_int(fd, buf, szp, typ)); + return (nni_copyout_int(fd, buf, szp, t)); } static void @@ -550,15 +551,15 @@ static nni_proto_pipe_ops surv0_pipe_ops = { .pipe_stop = surv0_pipe_stop, }; -static nni_proto_ctx_option surv0_ctx_options[] = { +static nni_proto_option surv0_ctx_options[] = { { - .co_name = NNG_OPT_SURVEYOR_SURVEYTIME, - .co_type = NNI_TYPE_DURATION, - .co_getopt = surv0_ctx_getopt_surveytime, - .co_setopt = surv0_ctx_setopt_surveytime, + .o_name = NNG_OPT_SURVEYOR_SURVEYTIME, + .o_type = NNI_TYPE_DURATION, + .o_get = surv0_ctx_get_surveytime, + .o_set = surv0_ctx_set_surveytime, }, { - .co_name = NULL, + .o_name = NULL, } }; static nni_proto_ctx_ops surv0_ctx_ops = { @@ -569,34 +570,32 @@ static nni_proto_ctx_ops surv0_ctx_ops = { .ctx_options = surv0_ctx_options, }; -static nni_proto_sock_option surv0_sock_options[] = { +static nni_proto_option surv0_sock_options[] = { { - .pso_name = NNG_OPT_SURVEYOR_SURVEYTIME, - .pso_type = NNI_TYPE_DURATION, - .pso_getopt = surv0_sock_getopt_surveytime, - .pso_setopt = surv0_sock_setopt_surveytime, + .o_name = NNG_OPT_SURVEYOR_SURVEYTIME, + .o_type = NNI_TYPE_DURATION, + .o_get = surv0_sock_get_surveytime, + .o_set = surv0_sock_set_surveytime, }, { - .pso_name = NNG_OPT_MAXTTL, - .pso_type = NNI_TYPE_INT32, - .pso_getopt = surv0_sock_getopt_maxttl, - .pso_setopt = surv0_sock_setopt_maxttl, + .o_name = NNG_OPT_MAXTTL, + .o_type = NNI_TYPE_INT32, + .o_get = surv0_sock_get_maxttl, + .o_set = surv0_sock_set_maxttl, }, { - .pso_name = NNG_OPT_RECVFD, - .pso_type = NNI_TYPE_INT32, - .pso_getopt = surv0_sock_getopt_recvfd, - .pso_setopt = NULL, + .o_name = NNG_OPT_RECVFD, + .o_type = NNI_TYPE_INT32, + .o_get = surv0_sock_get_recvfd, }, { - .pso_name = NNG_OPT_SENDFD, - .pso_type = NNI_TYPE_INT32, - .pso_getopt = surv0_sock_getopt_sendfd, - .pso_setopt = NULL, + .o_name = NNG_OPT_SENDFD, + .o_type = NNI_TYPE_INT32, + .o_get = surv0_sock_get_sendfd, }, // terminate list { - .pso_name = NULL, + .o_name = NULL, }, }; diff --git a/src/protocol/survey0/xrespond.c b/src/protocol/survey0/xrespond.c index 13a3d759..03a47e92 100644 --- a/src/protocol/survey0/xrespond.c +++ b/src/protocol/survey0/xrespond.c @@ -348,17 +348,17 @@ xresp0_putq_cb(void *arg) } static int -xresp0_sock_setopt_maxttl(void *arg, const void *buf, size_t sz, int typ) +xresp0_sock_set_maxttl(void *arg, const void *buf, size_t sz, nni_opt_type t) { xresp0_sock *s = arg; - return (nni_copyin_int(&s->ttl, buf, sz, 1, 255, typ)); + return (nni_copyin_int(&s->ttl, buf, sz, 1, 255, t)); } static int -xresp0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp, int typ) +xresp0_sock_get_maxttl(void *arg, void *buf, size_t *szp, nni_opt_type t) { xresp0_sock *s = arg; - return (nni_copyout_int(s->ttl, buf, szp, typ)); + return (nni_copyout_int(s->ttl, buf, szp, t)); } static void @@ -385,16 +385,16 @@ static nni_proto_pipe_ops xresp0_pipe_ops = { .pipe_stop = xresp0_pipe_stop, }; -static nni_proto_sock_option xresp0_sock_options[] = { +static nni_proto_option xresp0_sock_options[] = { { - .pso_name = NNG_OPT_MAXTTL, - .pso_type = NNI_TYPE_INT32, - .pso_getopt = xresp0_sock_getopt_maxttl, - .pso_setopt = xresp0_sock_setopt_maxttl, + .o_name = NNG_OPT_MAXTTL, + .o_type = NNI_TYPE_INT32, + .o_get = xresp0_sock_get_maxttl, + .o_set = xresp0_sock_set_maxttl, }, // terminate list { - .pso_name = NULL, + .o_name = NULL, }, }; diff --git a/src/protocol/survey0/xsurvey.c b/src/protocol/survey0/xsurvey.c index db21e688..bad24042 100644 --- a/src/protocol/survey0/xsurvey.c +++ b/src/protocol/survey0/xsurvey.c @@ -280,17 +280,17 @@ xsurv0_recv_cb(void *arg) } static int -xsurv0_sock_setopt_maxttl(void *arg, const void *buf, size_t sz, int typ) +xsurv0_sock_set_maxttl(void *arg, const void *buf, size_t sz, nni_opt_type t) { xsurv0_sock *s = arg; - return (nni_copyin_int(&s->ttl, buf, sz, 1, 255, typ)); + return (nni_copyin_int(&s->ttl, buf, sz, 1, 255, t)); } static int -xsurv0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp, int typ) +xsurv0_sock_get_maxttl(void *arg, void *buf, size_t *szp, nni_opt_type t) { xsurv0_sock *s = arg; - return (nni_copyout_int(s->ttl, buf, szp, typ)); + return (nni_copyout_int(s->ttl, buf, szp, t)); } static void @@ -356,16 +356,16 @@ static nni_proto_pipe_ops xsurv0_pipe_ops = { .pipe_stop = xsurv0_pipe_stop, }; -static nni_proto_sock_option xsurv0_sock_options[] = { +static nni_proto_option xsurv0_sock_options[] = { { - .pso_name = NNG_OPT_MAXTTL, - .pso_type = NNI_TYPE_INT32, - .pso_getopt = xsurv0_sock_getopt_maxttl, - .pso_setopt = xsurv0_sock_setopt_maxttl, + .o_name = NNG_OPT_MAXTTL, + .o_type = NNI_TYPE_INT32, + .o_get = xsurv0_sock_get_maxttl, + .o_set = xsurv0_sock_set_maxttl, }, // terminate list { - .pso_name = NULL, + .o_name = NULL, }, }; |
