You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by wi...@apache.org on 2020/01/13 19:42:04 UTC

[couchdb-mochiweb] 05/37: Conditional ssl:handshake/2

This is an automated email from the ASF dual-hosted git repository.

willholley pushed a commit to branch upstream
in repository https://gitbox.apache.org/repos/asf/couchdb-mochiweb.git

commit 105c9cb1af15dafcdc393cce04ffac65305e91dd
Author: Bob Ippolito <bo...@redivi.com>
AuthorDate: Thu Jan 10 12:16:29 2019 -0800

    Conditional ssl:handshake/2
---
 rebar.config            |  3 ++-
 src/mochiweb_socket.erl | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/rebar.config b/rebar.config
index adc1d78..0c6180d 100644
--- a/rebar.config
+++ b/rebar.config
@@ -4,7 +4,8 @@
             {platform_define, "^(R14|R15|R16B-)", 'crypto_compatibility'},
             {platform_define, "^(R14|R15|R16B|17)", 'rand_mod_unavailable'},
             {platform_define, "^(R14|R15|R16B|17)", 'sni_unavailable'},
-            {platform_define, "^(R14|R15|R16)", 'map_unavailable'}]}.
+            {platform_define, "^(R14|R15|R16)", 'map_unavailable'},
+            {platform_define, "^(R14|R15|R16|17|18|19|20)", 'ssl_handshake_unavailable'}]}.
 {cover_enabled, true}.
 {eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
 {dialyzer_opts, [{warnings, [no_return,
diff --git a/src/mochiweb_socket.erl b/src/mochiweb_socket.erl
index 8dc1b9d..9aeca2a 100644
--- a/src/mochiweb_socket.erl
+++ b/src/mochiweb_socket.erl
@@ -87,6 +87,17 @@ transport_accept({ssl, ListenSocket}) ->
 transport_accept(ListenSocket) ->
     gen_tcp:accept(ListenSocket, ?ACCEPT_TIMEOUT).
 
+-ifdef(ssl_handshake_unavailable).
+finish_accept({ssl, Socket}) ->
+    case ssl:ssl_accept(Socket, ?SSL_HANDSHAKE_TIMEOUT) of
+        ok ->
+            {ok, {ssl, Socket}};
+        {error, _} = Err ->
+            Err
+    end;
+finish_accept(Socket) ->
+    {ok, Socket}.
+-else.
 finish_accept({ssl, Socket}) ->
     case ssl:handshake(Socket, ?SSL_HANDSHAKE_TIMEOUT) of
         {ok, SslSocket} ->
@@ -96,6 +107,7 @@ finish_accept({ssl, Socket}) ->
     end;
 finish_accept(Socket) ->
     {ok, Socket}.
+-endif.
 
 recv({ssl, Socket}, Length, Timeout) ->
     ssl:recv(Socket, Length, Timeout);