Просмотр исходного кода

Add owner option to set owner of Websocket compression contexts

Required by Cowboy 2 because it initializes the contexts in a
different process than where they are used.
Loïc Hoguin 8 лет назад
Родитель
Сommit
d53cd5297e
1 измененных файлов с 10 добавлено и 0 удалено
  1. 10 0
      src/cow_ws.erl

+ 10 - 0
src/cow_ws.erl

@@ -149,6 +149,16 @@ init_permessage_deflate(InflateWindowBits, DeflateWindowBits, Opts) ->
 		-DeflateWindowBits2,
 		maps:get(mem_level, Opts, 8),
 		maps:get(strategy, Opts, default)),
+	%% Set the owner pid of the zlib contexts if requested.
+	_ = case Opts of
+		#{owner := Pid} ->
+			true = erlang:port_connect(Inflate, Pid),
+			true = unlink(Inflate),
+			true = erlang:port_connect(Deflate, Pid),
+			unlink(Deflate);
+		_ ->
+			true
+	end,
 	{Inflate, Deflate}.
 
 %% @doc Negotiate the x-webkit-deflate-frame extension.