Add send_node_release; no need for inc/decref when using post_node

This commit is contained in:
Tony Garnock-Jones 2011-01-09 17:16:07 -05:00
parent ce48a0fbea
commit 4ab09181c3
6 changed files with 10 additions and 14 deletions

View File

@ -58,9 +58,7 @@ static void factory_handle_message(node_t *n, sexp_t *m) {
} else {
reply = sexp_cons(sexp_cstring("create-failed"), sexp_cons(error, NULL));
}
INCREF(reply);
post_node(sexp_data(reply_sink), sexp_data(reply_name), reply, sexp_empty_bytes);
DECREF(reply, sexp_destructor);
}
}
return;

View File

@ -39,8 +39,6 @@ void announce_subscription(sexp_t *source,
msg = sexp_cons(filter, msg);
msg = sexp_cons(source, msg);
msg = sexp_cons(sexp_cstring(onoff ? "subscribed" : "unsubscribed"), msg);
INCREF(msg);
post_node(sexp_data(meta_sym), sexp_data(source), msg, NULL);
DECREF(msg, sexp_destructor);
}
}

View File

@ -159,7 +159,6 @@ void unbind_all_names_for_node(node_t *n) {
int post_node(cmsg_bytes_t node, cmsg_bytes_t name, sexp_t *body, sexp_t *token) {
static sexp_t *post_atom = NULL;
sexp_t *msg = NULL;
int result;
if (post_atom == NULL) {
post_atom = INCREF(sexp_cstring("post"));
@ -169,11 +168,7 @@ int post_node(cmsg_bytes_t node, cmsg_bytes_t name, sexp_t *body, sexp_t *token)
msg = sexp_cons(body, msg);
msg = sexp_cons(sexp_bytes(name), msg);
msg = sexp_cons(post_atom, msg);
INCREF(msg);
result = send_node(node, msg);
DECREF(msg, sexp_destructor);
return result;
return send_node_release(node, msg);
}
int send_node(cmsg_bytes_t node, sexp_t *message) {
@ -184,3 +179,11 @@ int send_node(cmsg_bytes_t node, sexp_t *message) {
n->node_class->handle_message(n, message);
return 1;
}
int send_node_release(cmsg_bytes_t node, sexp_t *message) {
int result;
INCREF(message);
result = send_node(node, message);
DECREF(message, sexp_destructor);
return result;
}

View File

@ -40,5 +40,6 @@ extern void unbind_all_names_for_node(node_t *n);
extern int post_node(cmsg_bytes_t node, cmsg_bytes_t name, sexp_t *body, sexp_t *token);
extern int send_node(cmsg_bytes_t node, sexp_t *message);
extern int send_node_release(cmsg_bytes_t node, sexp_t *message);
#endif

View File

@ -164,9 +164,7 @@ static void relay_main(node_t *n) {
sexp_t *reply_name = sexp_listref(args, 4);
if (bind_node(filter, n)) {
sexp_t *subok = sexp_cons(sexp_cstring("subscribe-ok"), sexp_cons(filter_sexp, NULL));
INCREF(subok);
post_node(sexp_data(reply_sink), sexp_data(reply_name), subok, sexp_empty_bytes);
DECREF(subok, sexp_destructor);
DECREF(r->remote_container_name, sexp_destructor);
r->remote_container_name = INCREF(filter_sexp);

View File

@ -114,9 +114,7 @@ subscription_t *handle_subscribe_message(sexp_t *source,
{
sexp_t *subok = sexp_cons(sexp_cstring("subscribe-ok"), sexp_cons(sub->uuid, NULL));
INCREF(subok);
post_node(sexp_data(reply_sink), sexp_data(reply_name), subok, sexp_empty_bytes);
DECREF(subok, sexp_destructor);
}
return sub;