From e1f991bd194dcbc8f2547ac4f583c998c727a1ec Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 4 Jan 2017 23:05:08 -0800 Subject: Fixes for TCP transport. Working now. --- src/transport/tcp/tcp.c | 8 ++++++-- tests/trantest.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index 249c2329..44841640 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -102,6 +102,7 @@ nni_tcp_pipe_recv(void *arg, nni_msg **msgp) uint8_t buf[sizeof (len)]; nni_iov iov[1]; int rv; + size_t sz; iov[0].iov_buf = buf; iov[0].iov_len = sizeof (buf); @@ -109,7 +110,6 @@ nni_tcp_pipe_recv(void *arg, nni_msg **msgp) return (rv); } NNI_GET64(buf, len); - // Check MAXRCVSIZE... if (len > pipe->rcvmax) { return (NNG_EPROTO); } @@ -118,7 +118,8 @@ nni_tcp_pipe_recv(void *arg, nni_msg **msgp) return (rv); } - iov[0].iov_buf = nng_msg_body(msg, &iov[0].iov_len); + iov[0].iov_len = len; + iov[0].iov_buf = nng_msg_body(msg, &sz); if ((rv = nni_plat_tcp_recv(&pipe->fd, iov, 1)) == 0) { *msgp = msg; @@ -177,6 +178,7 @@ nni_tcp_ep_init(void **epp, const char *url, uint16_t proto) ep->closed = 0; ep->proto = proto; ep->ipv4only = 0; + ep->rcvmax = 1024 * 1024; // XXX: fix this nni_plat_tcp_init(&ep->fd); (void) snprintf(ep->addr, sizeof (ep->addr), "%s", url); @@ -345,6 +347,7 @@ nni_tcp_ep_connect(void *arg, void **pipep) } nni_plat_tcp_init(&pipe->fd); pipe->proto = ep->proto; + pipe->rcvmax = ep->rcvmax; // Port is in the same place for both v4 and v6. remaddr.s_un.s_in.sa_port = port; @@ -410,6 +413,7 @@ nni_tcp_ep_accept(void *arg, void **pipep) return (NNG_ENOMEM); } pipe->proto = ep->proto; + pipe->rcvmax = ep->rcvmax; nni_plat_tcp_init(&pipe->fd); if ((rv = nni_plat_tcp_accept(&pipe->fd, &ep->fd)) != 0) { diff --git a/tests/trantest.h b/tests/trantest.h index 3bc47e8d..8898a9a5 100644 --- a/tests/trantest.h +++ b/tests/trantest.h @@ -82,14 +82,59 @@ trantest_listen_accept(trantest *tt) { Convey("Listen and accept" ,{ nng_endpoint *ep; + ep = NULL; So(nng_listen(tt->repsock, tt->addr, &ep, NNG_FLAG_SYNCH) == 0); So(ep != NULL); + ep = NULL; So(nng_dial(tt->reqsock, tt->addr, &ep, NNG_FLAG_SYNCH) == 0); So(ep != NULL); }) } +void +trantest_send_recv(trantest *tt) +{ + Convey("Send and recv", { + nng_endpoint *ep = NULL; + nng_msg *send; + nng_msg *recv; + char *body; + size_t len; + + ep = NULL; + So(nng_listen(tt->repsock, tt->addr, &ep, NNG_FLAG_SYNCH) == 0); + So(ep != NULL); + ep = NULL; + So(nng_dial(tt->reqsock, tt->addr, &ep, NNG_FLAG_SYNCH) == 0); + So(ep != NULL); + + send = NULL; + So(nng_msg_alloc(&send, 0) == 0); + So(send != NULL); + So(nng_msg_append(send, "ping", 5) == 0); + + So(nng_sendmsg(tt->reqsock, send, 0) == 0); + recv = NULL; + So(nng_recvmsg(tt->repsock, &recv, 0) == 0); + So(recv != NULL); + So((body = nng_msg_body(recv, &len)) != NULL); + So(len == 5); + So(strcmp(body, "ping") == 0); + nng_msg_free(recv); + + len = strlen("acknowledge"); + So(nng_msg_alloc(&send, 0) == 0); + So(nng_msg_append(send, "acknowledge", len) == 0); + So(nng_sendmsg(tt->repsock, send, 0) == 0); + So(nng_recvmsg(tt->reqsock, &recv, 0) == 0); + So(recv != NULL); + So((body = nng_msg_body(recv, &len)) != NULL); + So(len == strlen("acknowledge")); + So(strcmp(body, "acknowledge") == 0); + nng_msg_free(recv); + }) +} void trantest_test_all(const char *addr) { @@ -106,5 +151,6 @@ trantest_test_all(const char *addr) trantest_conn_refused(&tt); trantest_duplicate_listen(&tt); trantest_listen_accept(&tt); + trantest_send_recv(&tt); }) } -- cgit v1.2.3-70-g09d2