aboutsummaryrefslogtreecommitdiff
path: root/src/protocol
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-04 02:10:13 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-04 02:10:13 -0800
commit1d650869f32c56f6d49d898c38f7525191a60bd1 (patch)
tree7a27136068de192a3166ce40ea7a541f68be9d96 /src/protocol
parent856c5c8e2aa4e07b2b628dd194a63ae13dae7ae3 (diff)
downloadnng-1d650869f32c56f6d49d898c38f7525191a60bd1.tar.gz
nng-1d650869f32c56f6d49d898c38f7525191a60bd1.tar.bz2
nng-1d650869f32c56f6d49d898c38f7525191a60bd1.zip
Initial cut at TCP, totally untested beyond compilation.
This also adds checks in the protocols to verify that pipe peers are of the proper protocol.
Diffstat (limited to 'src/protocol')
-rw-r--r--src/protocol/pair/pair.c3
-rw-r--r--src/protocol/reqrep/rep.c3
-rw-r--r--src/protocol/reqrep/req.c7
3 files changed, 10 insertions, 3 deletions
diff --git a/src/protocol/pair/pair.c b/src/protocol/pair/pair.c
index cc906791..f86a9fa7 100644
--- a/src/protocol/pair/pair.c
+++ b/src/protocol/pair/pair.c
@@ -102,6 +102,9 @@ nni_pair_pipe_add(void *arg)
nni_pair_pipe *pp = arg;
nni_pair_sock *pair = pp->pair;
+ if (nni_pipe_peer(pp->pipe) != NNG_PROTO_PAIR) {
+ return (NNG_EPROTO);
+ }
if (pair->pipe != NULL) {
return (NNG_EBUSY); // Already have a peer, denied.
}
diff --git a/src/protocol/reqrep/rep.c b/src/protocol/reqrep/rep.c
index ca59d799..8c375b61 100644
--- a/src/protocol/reqrep/rep.c
+++ b/src/protocol/reqrep/rep.c
@@ -137,6 +137,9 @@ nni_rep_pipe_add(void *arg)
nni_rep_sock *rep = rp->rep;
int rv;
+ if (nni_pipe_peer(rp->pipe) != NNG_PROTO_REQ) {
+ return (NNG_EPROTO);
+ }
nni_mtx_lock(&rep->mx);
rv = nni_idhash_insert(rep->pipes, nni_pipe_id(rp->pipe), rp);
nni_mtx_unlock(&rep->mx);
diff --git a/src/protocol/reqrep/req.c b/src/protocol/reqrep/req.c
index 4ce66ab6..b9981c3c 100644
--- a/src/protocol/reqrep/req.c
+++ b/src/protocol/reqrep/req.c
@@ -138,9 +138,10 @@ nni_req_pipe_fini(void *arg)
static int
nni_req_pipe_add(void *arg)
{
- // We have nothing to do, since we don't need to maintain a global
- // list of related pipes.
- NNI_ARG_UNUSED(arg);
+ nni_req_pipe *rp = arg;
+ if (nni_pipe_peer(rp->pipe) != NNG_PROTO_REP) {
+ return (NNG_EPROTO);
+ }
return (0);
}