Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test_server): deprecated ssl_accept #48

Merged
merged 1 commit into from
May 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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