diff options
author | juhlig <[email protected]> | 2020-04-02 14:16:41 +0200 |
---|---|---|
committer | juhlig <[email protected]> | 2020-04-02 14:16:41 +0200 |
commit | 821937cea1a9afacd2dc2448440ad6f64d3a29f1 (patch) | |
tree | c866f0794c0a9185a4309a90de3001f08e3daee9 /src | |
parent | d9b833fcc9e862399e0e0e8aa624c611d71aaaed (diff) | |
download | ranch-821937cea1a9afacd2dc2448440ad6f64d3a29f1.tar.gz ranch-821937cea1a9afacd2dc2448440ad6f64d3a29f1.tar.bz2 ranch-821937cea1a9afacd2dc2448440ad6f64d3a29f1.zip |
Delete possibly existing socket file when listening on a local socket
Diffstat (limited to 'src')
-rw-r--r-- | src/ranch_ssl.erl | 9 | ||||
-rw-r--r-- | src/ranch_tcp.erl | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/ranch_ssl.erl b/src/ranch_ssl.erl index b86a35f..cc51012 100644 --- a/src/ranch_ssl.erl +++ b/src/ranch_ssl.erl @@ -124,6 +124,15 @@ do_listen(SocketOpts0, Logger) -> SocketOpts2 = ranch:set_option_default(SocketOpts1, nodelay, true), SocketOpts3 = ranch:set_option_default(SocketOpts2, send_timeout, 30000), SocketOpts = ranch:set_option_default(SocketOpts3, send_timeout_close, true), + %% In case of a local socket, we remove the socket file first. + %% It is possible to have multiple ip tuples in the socket options, + %% and the last one will be used (undocumented). + _ = case lists:keyfind(ip, 1, lists:reverse(SocketOpts0)) of + {ip, {local, SockFile}} -> + file:delete(SockFile); + _ -> + ok + end, %% We set the port to 0 because it is given in the Opts directly. %% The port in the options takes precedence over the one in the %% first argument. diff --git a/src/ranch_tcp.erl b/src/ranch_tcp.erl index 0d8da2e..4abd088 100644 --- a/src/ranch_tcp.erl +++ b/src/ranch_tcp.erl @@ -92,6 +92,15 @@ listen(TransOpts) -> SocketOpts2 = ranch:set_option_default(SocketOpts1, nodelay, true), SocketOpts3 = ranch:set_option_default(SocketOpts2, send_timeout, 30000), SocketOpts4 = ranch:set_option_default(SocketOpts3, send_timeout_close, true), + %% In case of a local socket, we remove the socket file first. + %% It is possible to have multiple ip tuples in the socket options, + %% and the last one will be used (undocumented). + _ = case lists:keyfind(ip, 1, lists:reverse(SocketOpts0)) of + {ip, {local, SockFile}} -> + file:delete(SockFile); + _ -> + ok + end, %% We set the port to 0 because it is given in the Opts directly. %% The port in the options takes precedence over the one in the %% first argument. |