Skip to content

Commit 7aecbfb

Browse files
committed
Support new Ranch options syntax
Starting with Ranch 2.0, you get a warning when mixing Ranch and TCP socket options in a single keyword list. We only support the old syntax, so you'll get warnings at startup, and presumably that syntax will stop working at some point. This diff adds support for the new syntax. It does so in a backwards compatible way, so you can upgrade Ranch and your option syntax either before or after upgrading elixir-thrift.
1 parent 779c7c7 commit 7aecbfb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/thrift/binary/framed/server.ex

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ defmodule Thrift.Binary.Framed.Server do
5454
transport_opts =
5555
opts
5656
|> Keyword.get(:transport_opts, [])
57-
|> Keyword.put(:port, port)
57+
|> add_port_to_transport_opts(port)
5858

5959
validate_ssl_configuration!(ssl_opts)
6060

@@ -75,6 +75,18 @@ defmodule Thrift.Binary.Framed.Server do
7575
)
7676
end
7777

78+
defp add_port_to_transport_opts(transport_opts, port) when is_list(transport_opts) do
79+
# Before Ranch 2.0, transport_opts is a keyword list with a mixture of
80+
# Ranch and socket opts.
81+
Keyword.put(transport_opts, :port, port)
82+
end
83+
84+
defp add_port_to_transport_opts(transport_opts, port) when is_map(transport_opts) do
85+
# After Ranch 2.0, transport_opts is a map with socket opts under its own
86+
# key.
87+
Map.update(transport_opts, :socket_opts, [port: port], &Keyword.put(&1, :port, port))
88+
end
89+
7890
@doc """
7991
Stops the server.
8092
"""

0 commit comments

Comments
 (0)