aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-08-03 08:17:50 +0200
committerLoïc Hoguin <[email protected]>2018-08-03 08:17:50 +0200
commit0e2e9f3bf6d5059f8af983ee38da94d7e5e47fa7 (patch)
tree76e4f39b176e604e6378717b9cd014ecd13dedd6
parent39a852a7c10d11105acdafe303d6eb393c68697e (diff)
downloadcowlib-0e2e9f3bf6d5059f8af983ee38da94d7e5e47fa7.tar.gz
cowlib-0e2e9f3bf6d5059f8af983ee38da94d7e5e47fa7.tar.bz2
cowlib-0e2e9f3bf6d5059f8af983ee38da94d7e5e47fa7.zip
Refactor some code to fix a Dialyzer warning
-rw-r--r--src/cow_ws.erl58
1 files changed, 35 insertions, 23 deletions
diff --git a/src/cow_ws.erl b/src/cow_ws.erl
index 48e161d..3d3807f 100644
--- a/src/cow_ws.erl
+++ b/src/cow_ws.erl
@@ -151,32 +151,44 @@ init_permessage_deflate(InflateWindowBits, DeflateWindowBits, Opts) ->
maps:get(mem_level, Opts, 8),
maps:get(strategy, Opts, default)),
%% Set the owner pid of the zlib contexts if requested.
- %%
- %% The zlib port became a reference in OTP 20.1+. There
- %% was however no way to change the controlling process
- %% until the OTP 20.1.3 patch version. Since we can't
- %% enable compression for 20.1, 20.1.1 and 20.1.2 we
- %% explicitly crash. The caller should ignore this extension.
- _ = case Opts of
- #{owner := Pid} when is_port(Inflate) ->
- true = erlang:port_connect(Inflate, Pid),
- true = unlink(Inflate),
- true = erlang:port_connect(Deflate, Pid),
- unlink(Deflate);
- #{owner := Pid} ->
- case erlang:function_exported(zlib, set_controlling_process, 2) of
- true ->
- zlib:set_controlling_process(Inflate, Pid),
- zlib:set_controlling_process(Deflate, Pid);
- false ->
- exit({error, incompatible_zlib_version,
- 'OTP 20.1, 20.1.1 and 20.1.2 are missing required functionality.'})
- end;
- _ ->
- true
+ case Opts of
+ #{owner := Pid} -> set_owner(Pid, Inflate, Deflate);
+ _ -> ok
end,
{Inflate, Deflate}.
+-ifdef(OTP_RELEASE).
+%% Using is_port/1 on a zlib context results in a Dialyzer warning in OTP 21.
+%% This function helps silence that warning while staying compatible
+%% with all supported versions.
+
+set_owner(Pid, Inflate, Deflate) ->
+ zlib:set_controlling_process(Inflate, Pid),
+ zlib:set_controlling_process(Deflate, Pid).
+-else.
+%% The zlib port became a reference in OTP 20.1+. There
+%% was however no way to change the controlling process
+%% until the OTP 20.1.3 patch version. Since we can't
+%% enable compression for 20.1, 20.1.1 and 20.1.2 we
+%% explicitly crash. The caller should ignore this extension.
+
+set_owner(Pid, Inflate, Deflate) when is_port(Inflate) ->
+ true = erlang:port_connect(Inflate, Pid),
+ true = unlink(Inflate),
+ true = erlang:port_connect(Deflate, Pid),
+ true = unlink(Deflate),
+ ok;
+set_owner(Pid, Inflate, Deflate) ->
+ case erlang:function_exported(zlib, set_controlling_process, 2) of
+ true ->
+ zlib:set_controlling_process(Inflate, Pid),
+ zlib:set_controlling_process(Deflate, Pid);
+ false ->
+ exit({error, incompatible_zlib_version,
+ 'OTP 20.1, 20.1.1 and 20.1.2 are missing required functionality.'})
+ end.
+-endif.
+
%% @doc Negotiate the x-webkit-deflate-frame extension.
%%
%% The implementation is very basic and none of the parameters