aboutsummaryrefslogtreecommitdiff
path: root/src/jid.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jid.erl')
-rw-r--r--src/jid.erl26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/jid.erl b/src/jid.erl
index 9e8ea9d23..287a0642b 100644
--- a/src/jid.erl
+++ b/src/jid.erl
@@ -52,11 +52,35 @@
-spec start() -> ok.
start() ->
+ {ok, Owner} = ets_owner(),
SplitPattern = binary:compile_pattern([<<"@">>, <<"/">>]),
- catch ets:new(jlib, [named_table, protected, set, {keypos, 1}]),
+ %% Table is public to allow ETS insert to fix / update the table even if table already exist
+ %% with another owner.
+ catch ets:new(jlib, [named_table, public, set, {keypos, 1}, {heir, Owner, undefined}]),
ets:insert(jlib, {string_to_jid_pattern, SplitPattern}),
ok.
+ets_owner() ->
+ case whereis(jlib_ets) of
+ undefined ->
+ Pid = spawn(fun() -> ets_keepalive() end),
+ case catch register(jlib_ets, Pid) of
+ true ->
+ {ok, Pid};
+ Error -> Error
+ end;
+ Pid ->
+ {ok,Pid}
+ end.
+
+%% Process used to keep jlib ETS table alive in case the original owner dies.
+%% The table need to be public, otherwise subsequent inserts would fail.
+ets_keepalive() ->
+ receive
+ _ ->
+ ets_keepalive()
+ end.
+
-spec make(binary(), binary(), binary()) -> jid() | error.
make(User, Server, Resource) ->