aboutsummaryrefslogtreecommitdiff
path: root/src/protocol
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-16 16:27:22 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-16 16:27:22 -0800
commitac8415c24ffea645105c3859e814843e81c97f8a (patch)
tree7b64b4aab3de6ce5bdd69c3d5b7ead57f4a4b4e7 /src/protocol
parentb8f7236aa2928d70d9bff2e1071654982539eeda (diff)
downloadnng-ac8415c24ffea645105c3859e814843e81c97f8a.tar.gz
nng-ac8415c24ffea645105c3859e814843e81c97f8a.tar.bz2
nng-ac8415c24ffea645105c3859e814843e81c97f8a.zip
Start of event framework.
This compiles correctly, but doesn't actually deliver events yet. As part of this, I've made most of the initializables in nng safe to tear-down if uninitialized (or set to zero e.g. via calloc). This makes it loads easier to write the teardown on error code, since I can deinit everything, without worrying about which things have been initialized and which have not.
Diffstat (limited to 'src/protocol')
-rw-r--r--src/protocol/bus/bus.c8
-rw-r--r--src/protocol/pair/pair.c8
-rw-r--r--src/protocol/pipeline/pull.c8
-rw-r--r--src/protocol/pipeline/push.c12
-rw-r--r--src/protocol/pubsub/pub.c10
-rw-r--r--src/protocol/pubsub/sub.c16
-rw-r--r--src/protocol/reqrep/rep.c16
-rw-r--r--src/protocol/reqrep/req.c20
-rw-r--r--src/protocol/survey/respond.c16
-rw-r--r--src/protocol/survey/survey.c10
10 files changed, 82 insertions, 42 deletions
diff --git a/src/protocol/bus/bus.c b/src/protocol/bus/bus.c
index 0d57f1db..986d8ed7 100644
--- a/src/protocol/bus/bus.c
+++ b/src/protocol/bus/bus.c
@@ -59,7 +59,9 @@ nni_bus_sock_fini(void *arg)
{
nni_bus_sock *psock = arg;
- NNI_FREE_STRUCT(psock);
+ if (psock != NULL) {
+ NNI_FREE_STRUCT(psock);
+ }
}
@@ -91,7 +93,9 @@ nni_bus_pipe_fini(void *arg)
{
nni_bus_pipe *ppipe = arg;
- NNI_FREE_STRUCT(ppipe);
+ if (ppipe != NULL) {
+ NNI_FREE_STRUCT(ppipe);
+ }
}
diff --git a/src/protocol/pair/pair.c b/src/protocol/pair/pair.c
index 0d8b32fe..d6c2eedf 100644
--- a/src/protocol/pair/pair.c
+++ b/src/protocol/pair/pair.c
@@ -64,7 +64,9 @@ nni_pair_sock_fini(void *arg)
{
nni_pair_sock *psock = arg;
- NNI_FREE_STRUCT(psock);
+ if (psock != NULL) {
+ NNI_FREE_STRUCT(psock);
+ }
}
@@ -89,7 +91,9 @@ nni_pair_pipe_fini(void *arg)
{
nni_pair_pipe *ppipe = arg;
- NNI_FREE_STRUCT(ppipe);
+ if (ppipe != NULL) {
+ NNI_FREE_STRUCT(ppipe);
+ }
}
diff --git a/src/protocol/pipeline/pull.c b/src/protocol/pipeline/pull.c
index 20beb873..ca15efef 100644
--- a/src/protocol/pipeline/pull.c
+++ b/src/protocol/pipeline/pull.c
@@ -50,7 +50,9 @@ nni_pull_sock_fini(void *arg)
{
nni_pull_sock *pull = arg;
- NNI_FREE_STRUCT(pull);
+ if (pull != NULL) {
+ NNI_FREE_STRUCT(pull);
+ }
}
@@ -74,7 +76,9 @@ nni_pull_pipe_fini(void *arg)
{
nni_pull_pipe *pp = arg;
- NNI_FREE_STRUCT(pp);
+ if (pp != NULL) {
+ NNI_FREE_STRUCT(pp);
+ }
}
diff --git a/src/protocol/pipeline/push.c b/src/protocol/pipeline/push.c
index 4704a323..0f973f8a 100644
--- a/src/protocol/pipeline/push.c
+++ b/src/protocol/pipeline/push.c
@@ -84,8 +84,10 @@ nni_push_sock_fini(void *arg)
{
nni_push_sock *push = arg;
- nni_cv_fini(&push->cv);
- NNI_FREE_STRUCT(push);
+ if (push != NULL) {
+ nni_cv_fini(&push->cv);
+ NNI_FREE_STRUCT(push);
+ }
}
@@ -116,8 +118,10 @@ nni_push_pipe_fini(void *arg)
{
nni_push_pipe *pp = arg;
- nni_msgq_fini(pp->mq);
- NNI_FREE_STRUCT(pp);
+ if (pp != NULL) {
+ nni_msgq_fini(pp->mq);
+ NNI_FREE_STRUCT(pp);
+ }
}
diff --git a/src/protocol/pubsub/pub.c b/src/protocol/pubsub/pub.c
index a167d523..5617d92c 100644
--- a/src/protocol/pubsub/pub.c
+++ b/src/protocol/pubsub/pub.c
@@ -62,7 +62,9 @@ nni_pub_sock_fini(void *arg)
{
nni_pub_sock *pub = arg;
- NNI_FREE_STRUCT(pub);
+ if (pub != NULL) {
+ NNI_FREE_STRUCT(pub);
+ }
}
@@ -93,8 +95,10 @@ nni_pub_pipe_fini(void *arg)
{
nni_pub_pipe *pp = arg;
- nni_msgq_fini(pp->sendq);
- NNI_FREE_STRUCT(pp);
+ if (pp != NULL) {
+ nni_msgq_fini(pp->sendq);
+ NNI_FREE_STRUCT(pp);
+ }
}
diff --git a/src/protocol/pubsub/sub.c b/src/protocol/pubsub/sub.c
index 9390b0d2..cd8dd87c 100644
--- a/src/protocol/pubsub/sub.c
+++ b/src/protocol/pubsub/sub.c
@@ -65,12 +65,14 @@ nni_sub_sock_fini(void *arg)
nni_sub_sock *sub = arg;
nni_sub_topic *topic;
- while ((topic = nni_list_first(&sub->topics)) != NULL) {
- nni_list_remove(&sub->topics, topic);
- nni_free(topic->buf, topic->len);
- NNI_FREE_STRUCT(topic);
+ if (sub != NULL) {
+ while ((topic = nni_list_first(&sub->topics)) != NULL) {
+ nni_list_remove(&sub->topics, topic);
+ nni_free(topic->buf, topic->len);
+ NNI_FREE_STRUCT(topic);
+ }
+ NNI_FREE_STRUCT(sub);
}
- NNI_FREE_STRUCT(sub);
}
@@ -94,7 +96,9 @@ nni_sub_pipe_fini(void *arg)
{
nni_sub_pipe *sp = arg;
- NNI_FREE_STRUCT(sp);
+ if (sp != NULL) {
+ NNI_FREE_STRUCT(sp);
+ }
}
diff --git a/src/protocol/reqrep/rep.c b/src/protocol/reqrep/rep.c
index 90346236..6410e6db 100644
--- a/src/protocol/reqrep/rep.c
+++ b/src/protocol/reqrep/rep.c
@@ -72,11 +72,13 @@ nni_rep_sock_fini(void *arg)
{
nni_rep_sock *rep = arg;
- nni_idhash_destroy(rep->pipes);
- if (rep->btrace != NULL) {
- nni_free(rep->btrace, rep->btrace_len);
+ if (rep != NULL) {
+ nni_idhash_destroy(rep->pipes);
+ if (rep->btrace != NULL) {
+ nni_free(rep->btrace, rep->btrace_len);
+ }
+ NNI_FREE_STRUCT(rep);
}
- NNI_FREE_STRUCT(rep);
}
@@ -106,8 +108,10 @@ nni_rep_pipe_fini(void *arg)
{
nni_rep_pipe *rp = arg;
- nni_msgq_fini(rp->sendq);
- NNI_FREE_STRUCT(rp);
+ if (rp != NULL) {
+ nni_msgq_fini(rp->sendq);
+ NNI_FREE_STRUCT(rp);
+ }
}
diff --git a/src/protocol/reqrep/req.c b/src/protocol/reqrep/req.c
index 73ef4969..787997e8 100644
--- a/src/protocol/reqrep/req.c
+++ b/src/protocol/reqrep/req.c
@@ -89,14 +89,16 @@ nni_req_sock_fini(void *arg)
{
nni_req_sock *req = arg;
- nni_cv_fini(&req->cv);
- if (req->reqmsg != NULL) {
- nni_msg_free(req->reqmsg);
- }
- if (req->retrymsg != NULL) {
- nni_msg_free(req->retrymsg);
+ if (req != NULL) {
+ nni_cv_fini(&req->cv);
+ if (req->reqmsg != NULL) {
+ nni_msg_free(req->reqmsg);
+ }
+ if (req->retrymsg != NULL) {
+ nni_msg_free(req->retrymsg);
+ }
+ NNI_FREE_STRUCT(req);
}
- NNI_FREE_STRUCT(req);
}
@@ -121,7 +123,9 @@ nni_req_pipe_fini(void *arg)
{
nni_req_pipe *rp = arg;
- NNI_FREE_STRUCT(rp);
+ if (rp != NULL) {
+ NNI_FREE_STRUCT(rp);
+ }
}
diff --git a/src/protocol/survey/respond.c b/src/protocol/survey/respond.c
index 0cef5a68..3a4bf52d 100644
--- a/src/protocol/survey/respond.c
+++ b/src/protocol/survey/respond.c
@@ -67,11 +67,13 @@ nni_resp_sock_fini(void *arg)
{
nni_resp_sock *psock = arg;
- nni_idhash_destroy(psock->pipes);
- if (psock->btrace != NULL) {
- nni_free(psock->btrace, psock->btrace_len);
+ if (psock != NULL) {
+ nni_idhash_destroy(psock->pipes);
+ if (psock->btrace != NULL) {
+ nni_free(psock->btrace, psock->btrace_len);
+ }
+ NNI_FREE_STRUCT(psock);
}
- NNI_FREE_STRUCT(psock);
}
@@ -101,8 +103,10 @@ nni_resp_pipe_fini(void *arg)
{
nni_resp_pipe *ppipe = arg;
- nni_msgq_fini(ppipe->sendq);
- NNI_FREE_STRUCT(ppipe);
+ if (ppipe != NULL) {
+ nni_msgq_fini(ppipe->sendq);
+ NNI_FREE_STRUCT(ppipe);
+ }
}
diff --git a/src/protocol/survey/survey.c b/src/protocol/survey/survey.c
index 22baf2e8..c7ce1c16 100644
--- a/src/protocol/survey/survey.c
+++ b/src/protocol/survey/survey.c
@@ -82,8 +82,10 @@ nni_surv_sock_fini(void *arg)
{
nni_surv_sock *psock = arg;
- nni_cv_fini(&psock->cv);
- NNI_FREE_STRUCT(psock);
+ if (psock != NULL) {
+ nni_cv_fini(&psock->cv);
+ NNI_FREE_STRUCT(psock);
+ }
}
@@ -114,7 +116,9 @@ nni_surv_pipe_fini(void *arg)
{
nni_surv_pipe *sp = arg;
- NNI_FREE_STRUCT(sp);
+ if (sp != NULL) {
+ NNI_FREE_STRUCT(sp);
+ }
}