diff options
author | Jan Uhlig <[email protected]> | 2021-09-01 12:30:33 +0200 |
---|---|---|
committer | Jan Uhlig <[email protected]> | 2021-09-01 12:30:33 +0200 |
commit | 4687f74954c1392da30c00f6031a2c99a2933834 (patch) | |
tree | b870e202b480b5c8e6ca12f42bb7a1ea02d0a8d3 /doc/src/guide/listeners.asciidoc | |
parent | 18816dfb0c3e01467855c0061023548db1655453 (diff) | |
download | ranch-4687f74954c1392da30c00f6031a2c99a2933834.tar.gz ranch-4687f74954c1392da30c00f6031a2c99a2933834.tar.bz2 ranch-4687f74954c1392da30c00f6031a2c99a2933834.zip |
Add post-listen callback
Diffstat (limited to 'doc/src/guide/listeners.asciidoc')
-rw-r--r-- | doc/src/guide/listeners.asciidoc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/doc/src/guide/listeners.asciidoc b/doc/src/guide/listeners.asciidoc index 0aee43c..779497c 100644 --- a/doc/src/guide/listeners.asciidoc +++ b/doc/src/guide/listeners.asciidoc @@ -177,6 +177,44 @@ file must not exist: Ranch must be able to create it. ]}, echo_protocol, [] ). +=== Performing additional setup steps on a listening socket + +If it is necessary to perform additional setup steps on the listening +socket, it is possible to specify a function with the transport option +`post_listen_callback`. This function will be called after the listening +socket has been created but before accepting connections on it, +with the socket as the single argument. + +The function must return either the atom `ok`, after which the listener +will start accepting connections on the socket, or a tuple +`{error, Reason}` which will cause the listener to fail starting with +`Reason`. + +.Setting permissions on a UNIX Domain socket file + +[source,erlang] +---- +PostListenCb = fun (Sock) -> + case ranch_tcp:sockname(Sock) of + {ok, {local, SockFile}} -> + file:change_mode(SockFile, 8#777); + {ok, _} -> + ok; + Error = {error, _} -> + Error + end +end, + +{ok, _} = ranch:start_listener(tcp_echo, + ranch_tcp, #{ + socket_opts => [ + {ip, {local, "/tmp/ranch_echo.sock"}}, + {port, 0}], + post_listen_callback => PostListenCb}, + echo_protocol, [] +). +---- + === Accepting connections on an existing socket If you want to accept connections on an existing socket, you can write |