Skip to content

Commit

Permalink
Add supervisor_options option to specify top-level supervisor options
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrudel committed Nov 9, 2023
1 parent 50e2b9f commit da6f372
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/thousand_island.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ defmodule ThousandIsland do
* `handler_module`: The name of the module used to handle connections to this server.
The module is expected to implement the `ThousandIsland.Handler` behaviour. Required
* `handler_options`: A term which is passed as the initial state value to
`c:ThousandIsland.Handler.handle_connection/2` calls. Optional, defaulting to nil.
* `genserver_options`: A term which is passed as the value to the handler module's
underlying `GenServer.start_link/3` call. Optional, defaulting to []
`c:ThousandIsland.Handler.handle_connection/2` calls. Optional, defaulting to nil
* `port`: The TCP port number to listen on. If not specified this defaults to 4000.
If a port number of `0` is given, the server will dynamically assign a port number
which can then be obtained via `ThousandIsland.listener_info/1` or
Expand All @@ -116,6 +114,11 @@ defmodule ThousandIsland do
`ThousandIsland.Transports.TCP` and `ThousandIsland.Transports.SSL` modules. Any options
in terms of interfaces to listen to / certificates and keys to use for SSL connections
will be passed in via this option
* `genserver_options`: A term which is passed as the option value to the handler module's
underlying `GenServer.start_link/3` call. Optional, defaulting to `[]`
* `supervisor_options`: A term which is passed as the option value to this server's top-level
supervisor's `Supervisor.start_link/3` call. Useful for setting the `name` for this server.
Optional, defaulting to `[]`
* `num_acceptors`: The number of acceptor processes to run. Defaults to 100
* `num_connections`: The maximum number of concurrent connections which each acceptor will
accept before throttling connections. Connections will be throttled by having the acceptor
Expand Down Expand Up @@ -145,6 +148,7 @@ defmodule ThousandIsland do
handler_module: module(),
handler_options: term(),
genserver_options: GenServer.options(),
supervisor_options: [Supervisor.option()],
port: :inet.port_number(),
transport_module: module(),
transport_options: transport_options(),
Expand Down
2 changes: 1 addition & 1 deletion lib/thousand_island/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule ThousandIsland.Server do

@spec start_link(ThousandIsland.ServerConfig.t()) :: Supervisor.on_start()
def start_link(%ThousandIsland.ServerConfig{} = config) do
Supervisor.start_link(__MODULE__, config)
Supervisor.start_link(__MODULE__, config, config.supervisor_options)
end

@spec listener_pid(Supervisor.supervisor()) :: pid() | nil
Expand Down
2 changes: 2 additions & 0 deletions lib/thousand_island/server_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule ThousandIsland.ServerConfig do
handler_module: module(),
handler_options: term(),
genserver_options: GenServer.options(),
supervisor_options: [Supervisor.option()],
num_acceptors: pos_integer(),
num_connections: non_neg_integer() | :infinity,
max_connections_retry_count: non_neg_integer(),
Expand All @@ -24,6 +25,7 @@ defmodule ThousandIsland.ServerConfig do
handler_module: nil,
handler_options: [],
genserver_options: [],
supervisor_options: [],
num_acceptors: 100,
num_connections: 16_384,
max_connections_retry_count: 5,
Expand Down

0 comments on commit da6f372

Please sign in to comment.