Skip to content

Commit

Permalink
fix(test_server): deprecated ssl_accept
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 committed Apr 1, 2022
1 parent de0d2c5 commit 306f053
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/x509/test/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ defmodule X509.Test.Server do
"""
use GenServer

# ssl_accept was deprecated on OTP 21
@ssl_function if Code.ensure_loaded?(:ssl) and function_exported?(:ssl, :handshake, 3),
do: :handshake,
else: :ssl_accept

@doc """
Starts a test server for the given test suite.
Expand Down Expand Up @@ -78,15 +83,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 apply(:ssl, @ssl_function, [socket, opts, 1000]) do
{:ok, ssl_socket} ->
flush(ssl_socket)
:ssl.send(ssl_socket, response)
Expand Down

0 comments on commit 306f053

Please sign in to comment.