aboutsummaryrefslogtreecommitdiff
path: root/src/transport/tcp
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-11-15 17:47:54 -0800
committerGarrett D'Amore <garrett@damore.org>2020-11-15 17:47:54 -0800
commit249932f3a208260f6b9c99d778b22d51cfabe87b (patch)
tree4fd4826127e9c225d5232c39d4ae1db89b539689 /src/transport/tcp
parenteb328da56c3fc7167b536dcb206df0abb0f4a9b9 (diff)
downloadnng-249932f3a208260f6b9c99d778b22d51cfabe87b.tar.gz
nng-249932f3a208260f6b9c99d778b22d51cfabe87b.tar.bz2
nng-249932f3a208260f6b9c99d778b22d51cfabe87b.zip
fixes #1071 tran_chkopt can be cleaned up
This is a sweeping cleanup of the transport logic around options, and also harmonizes the names used when setting or getting options. Additionally, legacy methods are now moved into a separate file and can be elided via CMake or a preprocessor define. Fundamentally, the ability to set to transport options via the socket is deprecated; there are numerous problems with this and my earlier approaches to deal with this have been somewhat misguided. Further these approaches will not work with future protocol work that is planned (were some options need to be negotiated with peers at the time of connection establishment.) Documentation has been updated to reflect this. The test suites still make rather broad use of the older APIs, and will be converted later.
Diffstat (limited to 'src/transport/tcp')
-rw-r--r--src/transport/tcp/tcp.c52
1 files changed, 11 insertions, 41 deletions
diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c
index 02bc078e..cf0bfeb1 100644
--- a/src/transport/tcp/tcp.c
+++ b/src/transport/tcp/tcp.c
@@ -593,7 +593,7 @@ tcptran_pipe_getopt(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
tcptran_pipe *p = arg;
- return (nni_stream_getx(p->conn, name, buf, szp, t));
+ return (nni_stream_get(p->conn, name, buf, szp, t));
}
static void
@@ -863,11 +863,11 @@ tcptran_ep_init(tcptran_ep **epp, nng_url *url, nni_sock *sock)
#ifdef NNG_ENABLE_STATS
static const nni_stat_info rcv_max_info = {
- .si_name = "rcv_max",
- .si_desc = "maximum receive size",
- .si_type = NNG_STAT_LEVEL,
- .si_unit = NNG_UNIT_BYTES,
- .si_atomic = true,
+ .si_name = "rcv_max",
+ .si_desc = "maximum receive size",
+ .si_type = NNG_STAT_LEVEL,
+ .si_unit = NNG_UNIT_BYTES,
+ .si_atomic = true,
};
nni_stat_init(&ep->st_rcv_max, &rcv_max_info);
#endif
@@ -910,7 +910,7 @@ tcptran_dialer_init(void **dp, nng_url *url, nni_dialer *ndialer)
return (rv);
}
if ((srcsa.s_family != NNG_AF_UNSPEC) &&
- ((rv = nni_stream_dialer_setx(ep->dialer, NNG_OPT_LOCADDR, &srcsa,
+ ((rv = nni_stream_dialer_set(ep->dialer, NNG_OPT_LOCADDR, &srcsa,
sizeof(srcsa), NNI_TYPE_SOCKADDR)) != 0)) {
tcptran_ep_fini(ep);
return (rv);
@@ -1141,7 +1141,7 @@ tcptran_dialer_getopt(
tcptran_ep *ep = arg;
int rv;
- rv = nni_stream_dialer_getx(ep->dialer, name, buf, szp, t);
+ rv = nni_stream_dialer_get(ep->dialer, name, buf, szp, t);
if (rv == NNG_ENOTSUP) {
rv = nni_getopt(tcptran_ep_opts, name, ep, buf, szp, t);
}
@@ -1155,7 +1155,7 @@ tcptran_dialer_setopt(
tcptran_ep *ep = arg;
int rv;
- rv = nni_stream_dialer_setx(ep->dialer, name, buf, sz, t);
+ rv = nni_stream_dialer_set(ep->dialer, name, buf, sz, t);
if (rv == NNG_ENOTSUP) {
rv = nni_setopt(tcptran_ep_opts, name, ep, buf, sz, t);
}
@@ -1169,7 +1169,7 @@ tcptran_listener_getopt(
tcptran_ep *ep = arg;
int rv;
- rv = nni_stream_listener_getx(ep->listener, name, buf, szp, t);
+ rv = nni_stream_listener_get(ep->listener, name, buf, szp, t);
if (rv == NNG_ENOTSUP) {
rv = nni_getopt(tcptran_ep_opts, name, ep, buf, szp, t);
}
@@ -1183,40 +1183,13 @@ tcptran_listener_setopt(
tcptran_ep *ep = arg;
int rv;
- rv = nni_stream_listener_setx(ep->listener, name, buf, sz, t);
+ rv = nni_stream_listener_set(ep->listener, name, buf, sz, t);
if (rv == NNG_ENOTSUP) {
rv = nni_setopt(tcptran_ep_opts, name, ep, buf, sz, t);
}
return (rv);
}
-static int
-tcptran_check_recvmaxsz(const void *v, size_t sz, nni_type t)
-{
- return (nni_copyin_size(NULL, v, sz, 0, NNI_MAXSZ, t));
-}
-
-static nni_chkoption tcptran_checkopts[] = {
- {
- .o_name = NNG_OPT_RECVMAXSZ,
- .o_check = tcptran_check_recvmaxsz,
- },
- {
- .o_name = NULL,
- },
-};
-
-static int
-tcptran_checkopt(const char *name, const void *buf, size_t sz, nni_type t)
-{
- int rv;
- rv = nni_chkopt(tcptran_checkopts, name, buf, sz, t);
- if (rv == NNG_ENOTSUP) {
- rv = nni_stream_checkopt("tcp", name, buf, sz, t);
- }
- return (rv);
-}
-
static nni_tran_dialer_ops tcptran_dialer_ops = {
.d_init = tcptran_dialer_init,
.d_fini = tcptran_ep_fini,
@@ -1244,7 +1217,6 @@ static nni_tran tcp_tran = {
.tran_pipe = &tcptran_pipe_ops,
.tran_init = tcptran_init,
.tran_fini = tcptran_fini,
- .tran_checkopt = tcptran_checkopt,
};
static nni_tran tcp4_tran = {
@@ -1255,7 +1227,6 @@ static nni_tran tcp4_tran = {
.tran_pipe = &tcptran_pipe_ops,
.tran_init = tcptran_init,
.tran_fini = tcptran_fini,
- .tran_checkopt = tcptran_checkopt,
};
static nni_tran tcp6_tran = {
@@ -1266,7 +1237,6 @@ static nni_tran tcp6_tran = {
.tran_pipe = &tcptran_pipe_ops,
.tran_init = tcptran_init,
.tran_fini = tcptran_fini,
- .tran_checkopt = tcptran_checkopt,
};
int