aboutsummaryrefslogtreecommitdiff
path: root/src/transport/tcp
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-06-12 20:05:34 -0700
committerGarrett D'Amore <garrett@damore.org>2018-06-13 18:01:52 -0700
commitda2aac4a6eb10af88e3938068e24c58aea1832b1 (patch)
treefb0676be5426ed1510945b7e7fe3d09eb45333a7 /src/transport/tcp
parent61ffae5e3649897776c26799ccaaa35d578ba816 (diff)
downloadnng-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/transport/tcp')
-rw-r--r--src/transport/tcp/tcp.c451
1 files changed, 231 insertions, 220 deletions
diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c
index be0dd2b5..f23d5b3a 100644
--- a/src/transport/tcp/tcp.c
+++ b/src/transport/tcp/tcp.c
@@ -17,11 +17,11 @@
// TCP transport. Platform specific TCP operations must be
// supplied as well.
-typedef struct nni_tcp_pipe nni_tcp_pipe;
-typedef struct nni_tcp_ep nni_tcp_ep;
+typedef struct tcp_pipe tcp_pipe;
+typedef struct tcp_ep tcp_ep;
-// nni_tcp_pipe is one end of a TCP connection.
-struct nni_tcp_pipe {
+// tcp_pipe is one end of a TCP connection.
+struct tcp_pipe {
nni_plat_tcp_pipe *tpp;
uint16_t peer;
uint16_t proto;
@@ -46,7 +46,7 @@ struct nni_tcp_pipe {
nni_mtx mtx;
};
-struct nni_tcp_ep {
+struct tcp_ep {
nni_plat_tcp_ep *tep;
uint16_t proto;
size_t rcvmax;
@@ -60,28 +60,28 @@ struct nni_tcp_ep {
nni_mtx mtx;
};
-static void nni_tcp_pipe_dosend(nni_tcp_pipe *, nni_aio *);
-static void nni_tcp_pipe_dorecv(nni_tcp_pipe *);
-static void nni_tcp_pipe_send_cb(void *);
-static void nni_tcp_pipe_recv_cb(void *);
-static void nni_tcp_pipe_nego_cb(void *);
-static void nni_tcp_ep_cb(void *arg);
+static void tcp_pipe_dosend(tcp_pipe *, nni_aio *);
+static void tcp_pipe_dorecv(tcp_pipe *);
+static void tcp_pipe_send_cb(void *);
+static void tcp_pipe_recv_cb(void *);
+static void tcp_pipe_nego_cb(void *);
+static void tcp_ep_cb(void *arg);
static int
-nni_tcp_tran_init(void)
+tcp_tran_init(void)
{
return (0);
}
static void
-nni_tcp_tran_fini(void)
+tcp_tran_fini(void)
{
}
static void
-nni_tcp_pipe_close(void *arg)
+tcp_pipe_close(void *arg)
{
- nni_tcp_pipe *p = arg;
+ tcp_pipe *p = arg;
nni_aio_close(p->rxaio);
nni_aio_close(p->txaio);
@@ -91,9 +91,9 @@ nni_tcp_pipe_close(void *arg)
}
static void
-nni_tcp_pipe_stop(void *arg)
+tcp_pipe_stop(void *arg)
{
- nni_tcp_pipe *p = arg;
+ tcp_pipe *p = arg;
nni_aio_stop(p->rxaio);
nni_aio_stop(p->txaio);
@@ -101,9 +101,9 @@ nni_tcp_pipe_stop(void *arg)
}
static void
-nni_tcp_pipe_fini(void *arg)
+tcp_pipe_fini(void *arg)
{
- nni_tcp_pipe *p = arg;
+ tcp_pipe *p = arg;
nni_aio_fini(p->rxaio);
nni_aio_fini(p->txaio);
@@ -119,19 +119,19 @@ nni_tcp_pipe_fini(void *arg)
}
static int
-nni_tcp_pipe_init(nni_tcp_pipe **pipep, nni_tcp_ep *ep, void *tpp)
+tcp_pipe_init(tcp_pipe **pipep, tcp_ep *ep, void *tpp)
{
- nni_tcp_pipe *p;
- int rv;
+ tcp_pipe *p;
+ int rv;
if ((p = NNI_ALLOC_STRUCT(p)) == NULL) {
return (NNG_ENOMEM);
}
nni_mtx_init(&p->mtx);
- if (((rv = nni_aio_init(&p->txaio, nni_tcp_pipe_send_cb, p)) != 0) ||
- ((rv = nni_aio_init(&p->rxaio, nni_tcp_pipe_recv_cb, p)) != 0) ||
- ((rv = nni_aio_init(&p->negaio, nni_tcp_pipe_nego_cb, p)) != 0)) {
- nni_tcp_pipe_fini(p);
+ if (((rv = nni_aio_init(&p->txaio, tcp_pipe_send_cb, p)) != 0) ||
+ ((rv = nni_aio_init(&p->rxaio, tcp_pipe_recv_cb, p)) != 0) ||
+ ((rv = nni_aio_init(&p->negaio, tcp_pipe_nego_cb, p)) != 0)) {
+ tcp_pipe_fini(p);
return (rv);
}
nni_aio_list_init(&p->recvq);
@@ -154,9 +154,9 @@ nni_tcp_pipe_init(nni_tcp_pipe **pipep, nni_tcp_ep *ep, void *tpp)
}
static void
-nni_tcp_cancel_nego(nni_aio *aio, int rv)
+tcp_cancel_nego(nni_aio *aio, int rv)
{
- nni_tcp_pipe *p = nni_aio_get_prov_data(aio);
+ tcp_pipe *p = nni_aio_get_prov_data(aio);
nni_mtx_lock(&p->mtx);
if (p->user_negaio != aio) {
@@ -171,11 +171,11 @@ nni_tcp_cancel_nego(nni_aio *aio, int rv)
}
static void
-nni_tcp_pipe_nego_cb(void *arg)
+tcp_pipe_nego_cb(void *arg)
{
- nni_tcp_pipe *p = arg;
- nni_aio * aio = p->negaio;
- int rv;
+ tcp_pipe *p = arg;
+ nni_aio * aio = p->negaio;
+ int rv;
nni_mtx_lock(&p->mtx);
if ((rv = nni_aio_result(aio)) != 0) {
@@ -228,14 +228,14 @@ done:
}
static void
-nni_tcp_pipe_send_cb(void *arg)
+tcp_pipe_send_cb(void *arg)
{
- nni_tcp_pipe *p = arg;
- int rv;
- nni_aio * aio;
- size_t n;
- nni_msg * msg;
- nni_aio * txaio = p->txaio;
+ tcp_pipe *p = arg;
+ int rv;
+ nni_aio * aio;
+ size_t n;
+ nni_msg * msg;
+ nni_aio * txaio = p->txaio;
nni_mtx_lock(&p->mtx);
aio = nni_list_first(&p->sendq);
@@ -263,7 +263,7 @@ nni_tcp_pipe_send_cb(void *arg)
nni_aio_list_remove(aio);
if (!nni_list_empty(&p->sendq)) {
// schedule next send
- nni_tcp_pipe_dosend(p, nni_list_first(&p->sendq));
+ tcp_pipe_dosend(p, nni_list_first(&p->sendq));
}
nni_mtx_unlock(&p->mtx);
@@ -275,14 +275,14 @@ nni_tcp_pipe_send_cb(void *arg)
}
static void
-nni_tcp_pipe_recv_cb(void *arg)
+tcp_pipe_recv_cb(void *arg)
{
- nni_tcp_pipe *p = arg;
- nni_aio * aio;
- int rv;
- size_t n;
- nni_msg * msg;
- nni_aio * rxaio = p->rxaio;
+ tcp_pipe *p = arg;
+ nni_aio * aio;
+ int rv;
+ size_t n;
+ nni_msg * msg;
+ nni_aio * rxaio = p->rxaio;
nni_mtx_lock(&p->mtx);
aio = nni_list_first(&p->recvq);
@@ -337,7 +337,7 @@ nni_tcp_pipe_recv_cb(void *arg)
msg = p->rxmsg;
p->rxmsg = NULL;
if (!nni_list_empty(&p->recvq)) {
- nni_tcp_pipe_dorecv(p);
+ tcp_pipe_dorecv(p);
}
nni_mtx_unlock(&p->mtx);
@@ -358,9 +358,9 @@ recv_error:
}
static void
-nni_tcp_cancel_tx(nni_aio *aio, int rv)
+tcp_cancel_tx(nni_aio *aio, int rv)
{
- nni_tcp_pipe *p = nni_aio_get_prov_data(aio);
+ tcp_pipe *p = nni_aio_get_prov_data(aio);
nni_mtx_lock(&p->mtx);
if (!nni_aio_list_active(aio)) {
@@ -382,7 +382,7 @@ nni_tcp_cancel_tx(nni_aio *aio, int rv)
}
static void
-nni_tcp_pipe_dosend(nni_tcp_pipe *p, nni_aio *aio)
+tcp_pipe_dosend(tcp_pipe *p, nni_aio *aio)
{
nni_aio *txaio;
nni_msg *msg;
@@ -416,31 +416,31 @@ nni_tcp_pipe_dosend(nni_tcp_pipe *p, nni_aio *aio)
}
static void
-nni_tcp_pipe_send(void *arg, nni_aio *aio)
+tcp_pipe_send(void *arg, nni_aio *aio)
{
- nni_tcp_pipe *p = arg;
- int rv;
+ tcp_pipe *p = arg;
+ int rv;
if (nni_aio_begin(aio) != 0) {
return;
}
nni_mtx_lock(&p->mtx);
- if ((rv = nni_aio_schedule(aio, nni_tcp_cancel_tx, p)) != 0) {
+ if ((rv = nni_aio_schedule(aio, tcp_cancel_tx, p)) != 0) {
nni_mtx_unlock(&p->mtx);
nni_aio_finish_error(aio, rv);
return;
}
nni_list_append(&p->sendq, aio);
if (nni_list_first(&p->sendq) == aio) {
- nni_tcp_pipe_dosend(p, aio);
+ tcp_pipe_dosend(p, aio);
}
nni_mtx_unlock(&p->mtx);
}
static void
-nni_tcp_cancel_rx(nni_aio *aio, int rv)
+tcp_cancel_rx(nni_aio *aio, int rv)
{
- nni_tcp_pipe *p = nni_aio_get_prov_data(aio);
+ tcp_pipe *p = nni_aio_get_prov_data(aio);
nni_mtx_lock(&p->mtx);
if (!nni_aio_list_active(aio)) {
@@ -461,7 +461,7 @@ nni_tcp_cancel_rx(nni_aio *aio, int rv)
}
static void
-nni_tcp_pipe_dorecv(nni_tcp_pipe *p)
+tcp_pipe_dorecv(tcp_pipe *p)
{
nni_aio *rxaio;
nni_iov iov;
@@ -477,16 +477,16 @@ nni_tcp_pipe_dorecv(nni_tcp_pipe *p)
}
static void
-nni_tcp_pipe_recv(void *arg, nni_aio *aio)
+tcp_pipe_recv(void *arg, nni_aio *aio)
{
- nni_tcp_pipe *p = arg;
- int rv;
+ tcp_pipe *p = arg;
+ int rv;
if (nni_aio_begin(aio) != 0) {
return;
}
nni_mtx_lock(&p->mtx);
- if ((rv = nni_aio_schedule(aio, nni_tcp_cancel_rx, p)) != 0) {
+ if ((rv = nni_aio_schedule(aio, tcp_cancel_rx, p)) != 0) {
nni_mtx_unlock(&p->mtx);
nni_aio_finish_error(aio, rv);
return;
@@ -494,75 +494,75 @@ nni_tcp_pipe_recv(void *arg, nni_aio *aio)
nni_list_append(&p->recvq, aio);
if (nni_list_first(&p->recvq) == aio) {
- nni_tcp_pipe_dorecv(p);
+ tcp_pipe_dorecv(p);
}
nni_mtx_unlock(&p->mtx);
}
static uint16_t
-nni_tcp_pipe_peer(void *arg)
+tcp_pipe_peer(void *arg)
{
- nni_tcp_pipe *p = arg;
+ tcp_pipe *p = arg;
return (p->peer);
}
static int
-nni_tcp_pipe_getopt_locaddr(void *arg, void *v, size_t *szp, int typ)
+tcp_pipe_get_locaddr(void *arg, void *v, size_t *szp, nni_opt_type t)
{
- nni_tcp_pipe *p = arg;
- int rv;
- nni_sockaddr sa;
+ tcp_pipe * p = arg;
+ int rv;
+ nni_sockaddr sa;
memset(&sa, 0, sizeof(sa));
if ((rv = nni_plat_tcp_pipe_sockname(p->tpp, &sa)) == 0) {
- rv = nni_copyout_sockaddr(&sa, v, szp, typ);
+ rv = nni_copyout_sockaddr(&sa, v, szp, t);
}
return (rv);
}
static int
-nni_tcp_pipe_getopt_remaddr(void *arg, void *v, size_t *szp, int typ)
+tcp_pipe_get_remaddr(void *arg, void *v, size_t *szp, nni_opt_type t)
{
- nni_tcp_pipe *p = arg;
- int rv;
- nni_sockaddr sa;
+ tcp_pipe * p = arg;
+ int rv;
+ nni_sockaddr sa;
memset(&sa, 0, sizeof(sa));
if ((rv = nni_plat_tcp_pipe_peername(p->tpp, &sa)) == 0) {
- rv = nni_copyout_sockaddr(&sa, v, szp, typ);
+ rv = nni_copyout_sockaddr(&sa, v, szp, t);
}
return (rv);
}
static int
-nni_tcp_pipe_getopt_keepalive(void *arg, void *v, size_t *szp, int typ)
+tcp_pipe_get_keepalive(void *arg, void *v, size_t *szp, nni_opt_type t)
{
- nni_tcp_pipe *p = arg;
- return (nni_copyout_bool(p->keepalive, v, szp, typ));
+ tcp_pipe *p = arg;
+ return (nni_copyout_bool(p->keepalive, v, szp, t));
}
static int
-nni_tcp_pipe_getopt_nodelay(void *arg, void *v, size_t *szp, int typ)
+tcp_pipe_get_nodelay(void *arg, void *v, size_t *szp, nni_opt_type t)
{
- nni_tcp_pipe *p = arg;
- return (nni_copyout_bool(p->nodelay, v, szp, typ));
+ tcp_pipe *p = arg;
+ return (nni_copyout_bool(p->nodelay, v, szp, t));
}
// Note that the url *must* be in a modifiable buffer.
static void
-nni_tcp_pipe_start(void *arg, nni_aio *aio)
+tcp_pipe_start(void *arg, nni_aio *aio)
{
- nni_tcp_pipe *p = arg;
- nni_aio * negaio;
- nni_iov iov;
- int rv;
+ tcp_pipe *p = arg;
+ nni_aio * negaio;
+ nni_iov iov;
+ int rv;
if (nni_aio_begin(aio) != 0) {
return;
}
nni_mtx_lock(&p->mtx);
- if ((rv = nni_aio_schedule(aio, nni_tcp_cancel_nego, p)) != 0) {
+ if ((rv = nni_aio_schedule(aio, tcp_cancel_nego, p)) != 0) {
nni_mtx_unlock(&p->mtx);
nni_aio_finish_error(aio, rv);
return;
@@ -588,9 +588,9 @@ nni_tcp_pipe_start(void *arg, nni_aio *aio)
}
static void
-nni_tcp_ep_fini(void *arg)
+tcp_ep_fini(void *arg)
{
- nni_tcp_ep *ep = arg;
+ tcp_ep *ep = arg;
nni_aio_stop(ep->aio);
if (ep->tep != NULL) {
@@ -602,9 +602,9 @@ nni_tcp_ep_fini(void *arg)
}
static int
-nni_tcp_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode)
+tcp_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode)
{
- nni_tcp_ep * ep;
+ tcp_ep * ep;
int rv;
char * host;
char * serv;
@@ -679,12 +679,12 @@ nni_tcp_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode)
ep->url = url;
if ((rv = nni_plat_tcp_ep_init(&ep->tep, &lsa, &rsa, mode)) != 0) {
- nni_tcp_ep_fini(ep);
+ tcp_ep_fini(ep);
return (rv);
}
- if ((rv = nni_aio_init(&ep->aio, nni_tcp_ep_cb, ep)) != 0) {
- nni_tcp_ep_fini(ep);
+ if ((rv = nni_aio_init(&ep->aio, tcp_ep_cb, ep)) != 0) {
+ tcp_ep_fini(ep);
return (rv);
}
ep->proto = nni_sock_proto_id(sock);
@@ -697,9 +697,9 @@ nni_tcp_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode)
}
static void
-nni_tcp_ep_close(void *arg)
+tcp_ep_close(void *arg)
{
- nni_tcp_ep *ep = arg;
+ tcp_ep *ep = arg;
nni_aio_close(ep->aio);
@@ -709,10 +709,10 @@ nni_tcp_ep_close(void *arg)
}
static int
-nni_tcp_ep_bind(void *arg)
+tcp_ep_bind(void *arg)
{
- nni_tcp_ep *ep = arg;
- int rv;
+ tcp_ep *ep = arg;
+ int rv;
nni_mtx_lock(&ep->mtx);
rv = nni_plat_tcp_ep_listen(ep->tep, &ep->bsa);
@@ -722,11 +722,11 @@ nni_tcp_ep_bind(void *arg)
}
static void
-nni_tcp_ep_finish(nni_tcp_ep *ep)
+tcp_ep_finish(tcp_ep *ep)
{
- nni_aio * aio;
- int rv;
- nni_tcp_pipe *pipe = NULL;
+ nni_aio * aio;
+ int rv;
+ tcp_pipe *pipe = NULL;
if ((rv = nni_aio_result(ep->aio)) != 0) {
goto done;
@@ -735,7 +735,7 @@ nni_tcp_ep_finish(nni_tcp_ep *ep)
// Attempt to allocate the parent pipe. If this fails we'll
// drop the connection (ENOMEM probably).
- rv = nni_tcp_pipe_init(&pipe, ep, nni_aio_get_output(ep->aio, 0));
+ rv = tcp_pipe_init(&pipe, ep, nni_aio_get_output(ep->aio, 0));
done:
aio = ep->user_aio;
@@ -747,7 +747,7 @@ done:
return;
}
if (pipe != NULL) {
- nni_tcp_pipe_fini(pipe);
+ tcp_pipe_fini(pipe);
}
if (aio != NULL) {
NNI_ASSERT(rv != 0);
@@ -756,19 +756,19 @@ done:
}
static void
-nni_tcp_ep_cb(void *arg)
+tcp_ep_cb(void *arg)
{
- nni_tcp_ep *ep = arg;
+ tcp_ep *ep = arg;
nni_mtx_lock(&ep->mtx);
- nni_tcp_ep_finish(ep);
+ tcp_ep_finish(ep);
nni_mtx_unlock(&ep->mtx);
}
static void
-nni_tcp_cancel_ep(nni_aio *aio, int rv)
+tcp_cancel_ep(nni_aio *aio, int rv)
{
- nni_tcp_ep *ep = nni_aio_get_prov_data(aio);
+ tcp_ep *ep = nni_aio_get_prov_data(aio);
nni_mtx_lock(&ep->mtx);
if (ep->user_aio != aio) {
@@ -783,10 +783,10 @@ nni_tcp_cancel_ep(nni_aio *aio, int rv)
}
static void
-nni_tcp_ep_accept(void *arg, nni_aio *aio)
+tcp_ep_accept(void *arg, nni_aio *aio)
{
- nni_tcp_ep *ep = arg;
- int rv;
+ tcp_ep *ep = arg;
+ int rv;
if (nni_aio_begin(aio) != 0) {
return;
@@ -794,7 +794,7 @@ nni_tcp_ep_accept(void *arg, nni_aio *aio)
nni_mtx_lock(&ep->mtx);
NNI_ASSERT(ep->user_aio == NULL);
- if ((rv = nni_aio_schedule(aio, nni_tcp_cancel_ep, ep)) != 0) {
+ if ((rv = nni_aio_schedule(aio, tcp_cancel_ep, ep)) != 0) {
nni_mtx_unlock(&ep->mtx);
nni_aio_finish_error(aio, rv);
return;
@@ -806,10 +806,10 @@ nni_tcp_ep_accept(void *arg, nni_aio *aio)
}
static void
-nni_tcp_ep_connect(void *arg, nni_aio *aio)
+tcp_ep_connect(void *arg, nni_aio *aio)
{
- nni_tcp_ep *ep = arg;
- int rv;
+ tcp_ep *ep = arg;
+ int rv;
if (nni_aio_begin(aio) != 0) {
return;
@@ -817,7 +817,7 @@ nni_tcp_ep_connect(void *arg, nni_aio *aio)
nni_mtx_lock(&ep->mtx);
NNI_ASSERT(ep->user_aio == NULL);
- if ((rv = nni_aio_schedule(aio, nni_tcp_cancel_ep, ep)) != 0) {
+ if ((rv = nni_aio_schedule(aio, tcp_cancel_ep, ep)) != 0) {
nni_mtx_unlock(&ep->mtx);
nni_aio_finish_error(aio, rv);
return;
@@ -829,13 +829,12 @@ nni_tcp_ep_connect(void *arg, nni_aio *aio)
}
static int
-nni_tcp_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz, int typ)
+tcp_ep_set_recvmaxsz(void *arg, const void *v, size_t sz, nni_opt_type t)
{
- nni_tcp_ep *ep = arg;
- size_t val;
- int rv;
- rv = nni_copyin_size(&val, v, sz, 0, NNI_MAXSZ, typ);
- if ((rv == 0) && (ep != NULL)) {
+ tcp_ep *ep = arg;
+ size_t val;
+ int rv;
+ if ((rv = nni_copyin_size(&val, v, sz, 0, NNI_MAXSZ, t)) == 0) {
nni_mtx_lock(&ep->mtx);
ep->rcvmax = val;
nni_mtx_unlock(&ep->mtx);
@@ -844,13 +843,18 @@ nni_tcp_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz, int typ)
}
static int
-nni_tcp_ep_setopt_nodelay(void *arg, const void *v, size_t sz, int typ)
+tcp_ep_chk_recvmaxsz(const void *v, size_t sz, nni_opt_type t)
+{
+ return (nni_copyin_size(NULL, v, sz, 0, NNI_MAXSZ, t));
+}
+
+static int
+tcp_ep_set_nodelay(void *arg, const void *v, size_t sz, nni_opt_type t)
{
- nni_tcp_ep *ep = arg;
- bool val;
- int rv;
- rv = nni_copyin_bool(&val, v, sz, typ);
- if ((rv == 0) && (ep != NULL)) {
+ tcp_ep *ep = arg;
+ bool val;
+ int rv;
+ if ((rv = nni_copyin_bool(&val, v, sz, t)) == 0) {
nni_mtx_lock(&ep->mtx);
ep->nodelay = val;
nni_mtx_unlock(&ep->mtx);
@@ -859,20 +863,25 @@ nni_tcp_ep_setopt_nodelay(void *arg, const void *v, size_t sz, int typ)
}
static int
-nni_tcp_ep_getopt_nodelay(void *arg, void *v, size_t *szp, int typ)
+tcp_ep_chk_bool(const void *v, size_t sz, nni_opt_type t)
+{
+ return (nni_copyin_bool(NULL, v, sz, t));
+}
+
+static int
+tcp_ep_get_nodelay(void *arg, void *v, size_t *szp, nni_opt_type t)
{
- nni_tcp_ep *ep = arg;
- return (nni_copyout_bool(ep->nodelay, v, szp, typ));
+ tcp_ep *ep = arg;
+ return (nni_copyout_bool(ep->nodelay, v, szp, t));
}
static int
-nni_tcp_ep_setopt_keepalive(void *arg, const void *v, size_t sz, int typ)
+tcp_ep_set_keepalive(void *arg, const void *v, size_t sz, nni_opt_type t)
{
- nni_tcp_ep *ep = arg;
- bool val;
- int rv;
- rv = nni_copyin_bool(&val, v, sz, typ);
- if ((rv == 0) && (ep != NULL)) {
+ tcp_ep *ep = arg;
+ bool val;
+ int rv;
+ if ((rv = nni_copyin_bool(&val, v, sz, t)) == 0) {
nni_mtx_lock(&ep->mtx);
ep->keepalive = val;
nni_mtx_unlock(&ep->mtx);
@@ -881,148 +890,150 @@ nni_tcp_ep_setopt_keepalive(void *arg, const void *v, size_t sz, int typ)
}
static int
-nni_tcp_ep_getopt_keepalive(void *arg, void *v, size_t *szp, int typ)
+tcp_ep_get_keepalive(void *arg, void *v, size_t *szp, nni_opt_type t)
{
- nni_tcp_ep *ep = arg;
- return (nni_copyout_bool(ep->keepalive, v, szp, typ));
+ tcp_ep *ep = arg;
+ return (nni_copyout_bool(ep->keepalive, v, szp, t));
}
static int
-nni_tcp_ep_getopt_url(void *arg, void *v, size_t *szp, int typ)
+tcp_ep_get_url(void *arg, void *v, size_t *szp, nni_opt_type t)
{
- nni_tcp_ep *ep = arg;
- char ustr[128];
- char ipstr[48]; // max for IPv6 addresses including []
- char portstr[6]; // max for 16-bit port
+ tcp_ep *ep = arg;
+ char ustr[128];
+ char ipstr[48]; // max for IPv6 addresses including []
+ char portstr[6]; // max for 16-bit port
if (ep->mode == NNI_EP_MODE_DIAL) {
- return (nni_copyout_str(ep->url->u_rawurl, v, szp, typ));
+ return (nni_copyout_str(ep->url->u_rawurl, v, szp, t));
}
nni_plat_tcp_ntop(&ep->bsa, ipstr, portstr);
snprintf(ustr, sizeof(ustr), "tcp://%s:%s", ipstr, portstr);
- return (nni_copyout_str(ustr, v, szp, typ));
+ return (nni_copyout_str(ustr, v, szp, t));
}
static int
-nni_tcp_ep_getopt_recvmaxsz(void *arg, void *v, size_t *szp, int typ)
+tcp_ep_get_recvmaxsz(void *arg, void *v, size_t *szp, nni_opt_type t)
{
- nni_tcp_ep *ep = arg;
- return (nni_copyout_size(ep->rcvmax, v, szp, typ));
+ tcp_ep *ep = arg;
+ return (nni_copyout_size(ep->rcvmax, v, szp, t));
}
-static nni_tran_pipe_option nni_tcp_pipe_options[] = {
+static nni_tran_option tcp_pipe_options[] = {
{
- .po_name = NNG_OPT_LOCADDR,
- .po_type = NNI_TYPE_SOCKADDR,
- .po_getopt = nni_tcp_pipe_getopt_locaddr,
+ .o_name = NNG_OPT_LOCADDR,
+ .o_type = NNI_TYPE_SOCKADDR,
+ .o_get = tcp_pipe_get_locaddr,
},
{
- .po_name = NNG_OPT_REMADDR,
- .po_type = NNI_TYPE_SOCKADDR,
- .po_getopt = nni_tcp_pipe_getopt_remaddr,
+ .o_name = NNG_OPT_REMADDR,
+ .o_type = NNI_TYPE_SOCKADDR,
+ .o_get = tcp_pipe_get_remaddr,
},
{
- .po_name = NNG_OPT_TCP_KEEPALIVE,
- .po_type = NNI_TYPE_BOOL,
- .po_getopt = nni_tcp_pipe_getopt_keepalive,
+ .o_name = NNG_OPT_TCP_KEEPALIVE,
+ .o_type = NNI_TYPE_BOOL,
+ .o_get = tcp_pipe_get_keepalive,
},
{
- .po_name = NNG_OPT_TCP_NODELAY,
- .po_type = NNI_TYPE_BOOL,
- .po_getopt = nni_tcp_pipe_getopt_nodelay,
+ .o_name = NNG_OPT_TCP_NODELAY,
+ .o_type = NNI_TYPE_BOOL,
+ .o_get = tcp_pipe_get_nodelay,
},
// terminate list
{
- .po_name = NULL,
+ .o_name = NULL,
},
};
-static nni_tran_pipe_ops nni_tcp_pipe_ops = {
- .p_fini = nni_tcp_pipe_fini,
- .p_start = nni_tcp_pipe_start,
- .p_stop = nni_tcp_pipe_stop,
- .p_send = nni_tcp_pipe_send,
- .p_recv = nni_tcp_pipe_recv,
- .p_close = nni_tcp_pipe_close,
- .p_peer = nni_tcp_pipe_peer,
- .p_options = nni_tcp_pipe_options,
+static nni_tran_pipe_ops tcp_pipe_ops = {
+ .p_fini = tcp_pipe_fini,
+ .p_start = tcp_pipe_start,
+ .p_stop = tcp_pipe_stop,
+ .p_send = tcp_pipe_send,
+ .p_recv = tcp_pipe_recv,
+ .p_close = tcp_pipe_close,
+ .p_peer = tcp_pipe_peer,
+ .p_options = tcp_pipe_options,
};
-static nni_tran_ep_option nni_tcp_ep_options[] = {
+static nni_tran_option tcp_ep_options[] = {
{
- .eo_name = NNG_OPT_RECVMAXSZ,
- .eo_type = NNI_TYPE_SIZE,
- .eo_getopt = nni_tcp_ep_getopt_recvmaxsz,
- .eo_setopt = nni_tcp_ep_setopt_recvmaxsz,
+ .o_name = NNG_OPT_RECVMAXSZ,
+ .o_type = NNI_TYPE_SIZE,
+ .o_get = tcp_ep_get_recvmaxsz,
+ .o_set = tcp_ep_set_recvmaxsz,
+ .o_chk = tcp_ep_chk_recvmaxsz,
},
{
- .eo_name = NNG_OPT_URL,
- .eo_type = NNI_TYPE_STRING,
- .eo_getopt = nni_tcp_ep_getopt_url,
- .eo_setopt = NULL,
+ .o_name = NNG_OPT_URL,
+ .o_type = NNI_TYPE_STRING,
+ .o_get = tcp_ep_get_url,
},
{
- .eo_name = NNG_OPT_TCP_NODELAY,
- .eo_type = NNI_TYPE_BOOL,
- .eo_getopt = nni_tcp_ep_getopt_nodelay,
- .eo_setopt = nni_tcp_ep_setopt_nodelay,
+ .o_name = NNG_OPT_TCP_NODELAY,
+ .o_type = NNI_TYPE_BOOL,
+ .o_get = tcp_ep_get_nodelay,
+ .o_set = tcp_ep_set_nodelay,
+ .o_chk = tcp_ep_chk_bool,
},
{
- .eo_name = NNG_OPT_TCP_KEEPALIVE,
- .eo_type = NNI_TYPE_BOOL,
- .eo_getopt = nni_tcp_ep_getopt_keepalive,
- .eo_setopt = nni_tcp_ep_setopt_keepalive,
+ .o_name = NNG_OPT_TCP_KEEPALIVE,
+ .o_type = NNI_TYPE_BOOL,
+ .o_get = tcp_ep_get_keepalive,
+ .o_set = tcp_ep_set_keepalive,
+ .o_chk = tcp_ep_chk_bool,
},
// terminate list
{
- .eo_name = NULL,
+ .o_name = NULL,
},
};
-static nni_tran_ep_ops nni_tcp_ep_ops = {
- .ep_init = nni_tcp_ep_init,
- .ep_fini = nni_tcp_ep_fini,
- .ep_connect = nni_tcp_ep_connect,
- .ep_bind = nni_tcp_ep_bind,
- .ep_accept = nni_tcp_ep_accept,
- .ep_close = nni_tcp_ep_close,
- .ep_options = nni_tcp_ep_options,
+static nni_tran_ep_ops tcp_ep_ops = {
+ .ep_init = tcp_ep_init,
+ .ep_fini = tcp_ep_fini,
+ .ep_connect = tcp_ep_connect,
+ .ep_bind = tcp_ep_bind,
+ .ep_accept = tcp_ep_accept,
+ .ep_close = tcp_ep_close,
+ .ep_options = tcp_ep_options,
};
-static nni_tran nni_tcp_tran = {
+static nni_tran tcp_tran = {
.tran_version = NNI_TRANSPORT_VERSION,
.tran_scheme = "tcp",
- .tran_ep = &nni_tcp_ep_ops,
- .tran_pipe = &nni_tcp_pipe_ops,
- .tran_init = nni_tcp_tran_init,
- .tran_fini = nni_tcp_tran_fini,
+ .tran_ep = &tcp_ep_ops,
+ .tran_pipe = &tcp_pipe_ops,
+ .tran_init = tcp_tran_init,
+ .tran_fini = tcp_tran_fini,
};
-static nni_tran nni_tcp4_tran = {
+static nni_tran tcp4_tran = {
.tran_version = NNI_TRANSPORT_VERSION,
.tran_scheme = "tcp4",
- .tran_ep = &nni_tcp_ep_ops,
- .tran_pipe = &nni_tcp_pipe_ops,
- .tran_init = nni_tcp_tran_init,
- .tran_fini = nni_tcp_tran_fini,
+ .tran_ep = &tcp_ep_ops,
+ .tran_pipe = &tcp_pipe_ops,
+ .tran_init = tcp_tran_init,
+ .tran_fini = tcp_tran_fini,
};
-static nni_tran nni_tcp6_tran = {
+static nni_tran tcp6_tran = {
.tran_version = NNI_TRANSPORT_VERSION,
.tran_scheme = "tcp6",
- .tran_ep = &nni_tcp_ep_ops,
- .tran_pipe = &nni_tcp_pipe_ops,
- .tran_init = nni_tcp_tran_init,
- .tran_fini = nni_tcp_tran_fini,
+ .tran_ep = &tcp_ep_ops,
+ .tran_pipe = &tcp_pipe_ops,
+ .tran_init = tcp_tran_init,
+ .tran_fini = tcp_tran_fini,
};
int
nng_tcp_register(void)
{
int rv;
- if (((rv = nni_tran_register(&nni_tcp_tran)) != 0) ||
- ((rv = nni_tran_register(&nni_tcp4_tran)) != 0) ||
- ((rv = nni_tran_register(&nni_tcp6_tran)) != 0)) {
+ if (((rv = nni_tran_register(&tcp_tran)) != 0) ||
+ ((rv = nni_tran_register(&tcp4_tran)) != 0) ||
+ ((rv = nni_tran_register(&tcp6_tran)) != 0)) {
return (rv);
}
return (0);