Skip to content

Commit

Permalink
fix(test_server): deprecated ssl_accept (#48)
Browse files Browse the repository at this point in the history
OTP 21 deprecated the `:ssl.ssl_accept/3` function. So, we add a
compile check to determine which function to call. This library
supports Elixir 1.5 and so the OTP support must be present up to OTP 18.
  • Loading branch information
victorolinasc authored May 25, 2022
1 parent 4223e3e commit 8730c48
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/x509/test/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ defmodule X509.Test.Server do
end

defp worker(socket, suite, response) do
case :ssl.ssl_accept(
socket,
[
active: false,
sni_fun: X509.Test.Suite.sni_fun(suite),
reuse_sessions: false
] ++ log_opts(),
1000
) do
opts =
[
active: false,
sni_fun: X509.Test.Suite.sni_fun(suite),
reuse_sessions: false
] ++ log_opts()

case handshake(socket, opts, 1000) do
{:ok, ssl_socket} ->
flush(ssl_socket)
:ssl.send(ssl_socket, response)
Expand All @@ -97,6 +96,16 @@ defmodule X509.Test.Server do
end
end

if Code.ensure_loaded?(:ssl) and function_exported?(:ssl, :handshake, 3) do
defp handshake(socket, opts, timeout) do
:ssl.handshake(socket, opts, timeout)
end
else
defp handshake(socket, opts, timeout) do
:ssl.ssl_accept(socket, opts, timeout)
end
end

defp flush(ssl_socket) do
case :ssl.recv(ssl_socket, 0, 100) do
{:ok, _data} ->
Expand Down

0 comments on commit 8730c48

Please sign in to comment.