From 881e1a962121bd8d63d9548b71a9b27cb008ff63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=AD=90=E5=8D=9A?= <349832309@qq.com> Date: Fri, 26 Oct 2018 19:43:05 +0800 Subject: [PATCH] Add case for ets:match_object --- src/emqx_broker.erl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/emqx_broker.erl b/src/emqx_broker.erl index 0828d6be3..857090c25 100644 --- a/src/emqx_broker.erl +++ b/src/emqx_broker.erl @@ -260,11 +260,19 @@ subscription(Topic, Subscriber) -> -spec(subscribed(emqx_topic:topic(), pid() | emqx_types:subid() | emqx_types:subscriber()) -> boolean()). subscribed(Topic, SubPid) when is_binary(Topic), is_pid(SubPid) -> - {Match, _} = ets:match_object(?SUBOPTION, {{Topic, {SubPid, '_'}}, '_'}, 1), - length(Match) >= 1; + case ets:match_object(?SUBOPTION, {{Topic, {SubPid, '_'}}, '_'}, 1) of + {Match, _} -> + length(Match) >= 1; + '$end_of_table' -> + false + end; subscribed(Topic, SubId) when is_binary(Topic), ?is_subid(SubId) -> - {Match, _} = ets:match_object(?SUBOPTION, {{Topic, {'_', SubId}}, '_'}, 1), - length(Match) >= 1; + case ets:match_object(?SUBOPTION, {{Topic, {'_', SubId}}, '_'}, 1) of + {Match, _} -> + length(Match) >= 1; + '$end_of_table' -> + false + end; subscribed(Topic, {SubPid, SubId}) when is_binary(Topic), is_pid(SubPid), ?is_subid(SubId) -> ets:member(?SUBOPTION, {Topic, {SubPid, SubId}}).