From 4aa1c54a8a55402e1fc05fd9dea2eb9297e7d00f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Sat, 28 Feb 2009 17:45:52 +0000 Subject: [PATCH] Make sure replies to subscribe and unsubscribe methods arrive before any other action is taken. --- htsp.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/htsp.c b/htsp.c index 15eb5450..1b7a3bdc 100644 --- a/htsp.c +++ b/htsp.c @@ -414,11 +414,18 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in) if((ch = channel_find_by_identifier(chid)) == NULL) return htsp_error("Requested channel does not exist"); + + /* + * We send the reply here or the user will get the 'subscriptionStart' + * async message before the reply to 'subscribe'. + */ + htsp_reply(htsp, in, htsmsg_create()); + s = subscription_create_from_channel(ch, 500, "htsp", htsp_subscription_callback, htsp, sid); LIST_INSERT_HEAD(&htsp->htsp_subscriptions, s, ths_subscriber_link); - return htsmsg_create(); + return NULL; } @@ -438,12 +445,18 @@ htsp_method_unsubscribe(htsp_connection_t *htsp, htsmsg_t *in) if(s->ths_u32 == sid) break; + /* + * We send the reply here or the user will get the 'subscriptionStart' + * async message before the reply to 'subscribe'. + */ + htsp_reply(htsp, in, htsmsg_create()); + if(s == NULL) - return htsmsg_create(); /* Just say ok */ + return NULL; /* Subscription did not exist, but we don't really care */ LIST_REMOVE(s, ths_subscriber_link); subscription_unsubscribe(s); - return htsmsg_create(); + return NULL; }