From d09902fb0669542fb8be0072797daf6e0173e8e3 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 2 Jan 2011 22:08:30 -0500 Subject: [PATCH] Rearrange message dispatch procedures slightly --- direct.c | 21 ++++++++++++++------- fanout.c | 23 +++++++++++++++-------- main.c | 12 ++++++------ queue.c | 21 ++++++++++++++------- 4 files changed, 49 insertions(+), 28 deletions(-) diff --git a/direct.c b/direct.c index dfecc85..3162416 100644 --- a/direct.c +++ b/direct.c @@ -87,20 +87,27 @@ static void direct_handle_message(node_t *n, sexp_t *m) { } else { warn("Non-string routing key in direct\n"); } - } else if ((msglen == 6) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("subscribe"))) { + return; + } + + if ((msglen == 6) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("subscribe"))) { subscription_t *sub = handle_subscribe_message(&d->subscriptions, args); if (sub != NULL) { sexp_t *filter = sexp_listref(args, 0); hashtable_get(&d->routing_table, sexp_data(filter), (void **) &sub->link); hashtable_put(&d->routing_table, sexp_data(filter), sub); } - } else if ((msglen == 2) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("unsubscribe"))) { - handle_unsubscribe_message(&d->subscriptions, args); - } else { - warn("Message not understood in direct; selector <<%.*s>>, length %u\n", - selector.len, selector.bytes, - msglen); + return; } + + if ((msglen == 2) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("unsubscribe"))) { + handle_unsubscribe_message(&d->subscriptions, args); + return; + } + + warn("Message not understood in direct; selector <<%.*s>>, length %u\n", + selector.len, selector.bytes, + msglen); } static node_class_t direct_class = { diff --git a/fanout.c b/fanout.c index 02722d7..4f65dda 100644 --- a/fanout.c +++ b/fanout.c @@ -78,15 +78,22 @@ static void fanout_handle_message(node_t *n, sexp_t *m) { context.f = f; context.body = sexp_listref(args, 1); hashtable_foreach(&f->subscriptions, send_to_sub, &context); - } else if ((msglen == 6) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("subscribe"))) { - handle_subscribe_message(&f->subscriptions, args); - } else if ((msglen == 2) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("unsubscribe"))) { - handle_unsubscribe_message(&f->subscriptions, args); - } else { - warn("Message not understood in fanout; selector <<%.*s>>, length %u\n", - selector.len, selector.bytes, - msglen); + return; } + + if ((msglen == 6) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("subscribe"))) { + handle_subscribe_message(&f->subscriptions, args); + return; + } + + if ((msglen == 2) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("unsubscribe"))) { + handle_unsubscribe_message(&f->subscriptions, args); + return; + } + + warn("Message not understood in fanout; selector <<%.*s>>, length %u\n", + selector.len, selector.bytes, + msglen); } static node_class_t fanout_class = { diff --git a/main.c b/main.c index cb55f9c..78f4ae7 100644 --- a/main.c +++ b/main.c @@ -39,8 +39,7 @@ static void factory_handle_message(node_t *n, sexp_t *m) { selector = sexp_data(sexp_head(m)); args = sexp_tail(m); - if ((msglen == 5) - && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("create"))) { + if ((msglen == 5) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("create"))) { sexp_t *classname = sexp_listref(args, 0); sexp_t *ctor_arg = sexp_listref(args, 1); sexp_t *reply_sink = sexp_listref(args, 2); @@ -63,11 +62,12 @@ static void factory_handle_message(node_t *n, sexp_t *m) { DECREF(reply, sexp_destructor); } } - } else { - warn("Message not understood in factory; selector <<%.*s>>, length %u\n", - selector.len, selector.bytes, - msglen); + return; } + + warn("Message not understood in factory; selector <<%.*s>>, length %u\n", + selector.len, selector.bytes, + msglen); } static node_class_t factory_class = { diff --git a/queue.c b/queue.c index c011a56..14852f2 100644 --- a/queue.c +++ b/queue.c @@ -165,19 +165,26 @@ static void queue_handle_message(node_t *n, sexp_t *m) { if ((msglen == 4) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("post"))) { sexp_enqueue(q->backlog_q, sexp_listref(args, 1)); throck_shovel(q); - } else if ((msglen == 6) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("subscribe"))) { + return; + } + + if ((msglen == 6) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("subscribe"))) { subscription_t *sub = handle_subscribe_message(&q->subscriptions, args); if (sub != NULL) { enqueue(&q->waiter_q, sub); throck_shovel(q); } - } else if ((msglen == 2) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("unsubscribe"))) { - handle_unsubscribe_message(&q->subscriptions, args); - } else { - warn("Message not understood in queue; selector <<%.*s>>, length %u\n", - selector.len, selector.bytes, - msglen); + return; } + + if ((msglen == 2) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("unsubscribe"))) { + handle_unsubscribe_message(&q->subscriptions, args); + return; + } + + warn("Message not understood in queue; selector <<%.*s>>, length %u\n", + selector.len, selector.bytes, + msglen); } static node_class_t queue_class = {