Update some ProtocolHandler @spec's (#213)

start_link/5's @spec wasn't updated when it signature was last changed.
Also add a @spec to init/6 and mark some internal functions as private.

We only support :ranch_tcp at the moment, so that's explicitly enforced
in both the typespecs as well as the init/6 function head.
This commit is contained in:
Jon Parise 2017-02-07 12:11:03 -08:00 committed by GitHub
parent 13b3b74773
commit 8b050d8dd6
2 changed files with 16 additions and 8 deletions

View File

@ -5,19 +5,26 @@ defmodule Thrift.Binary.Framed.ProtocolHandler do
@default_timeout 20_000
@typedoc "A module that implements the :ranch_transport behaviour"
@type transport :: :ranch_tcp
@typedoc "Transport-specific options"
@type transport_opts :: :ranch_tcp.opts
alias Thrift.{
Protocol,
TApplicationException
}
require Logger
@spec start_link(reference, pid, module, {module, module}) :: GenServer.on_start
def start_link(ref, socket, transport, {server_module, handler_module, tcp_opts}) do
pid = spawn_link(__MODULE__, :init, [ref, socket, transport, server_module, handler_module, tcp_opts])
@spec start_link(reference, port, transport, {module, module, transport_opts}) :: GenServer.on_start
def start_link(ref, socket, transport, {server_module, handler_module, transport_opts}) do
pid = spawn_link(__MODULE__, :init, [ref, socket, transport, server_module, handler_module, transport_opts])
{:ok, pid}
end
def init(ref, socket, transport, server_module, handler_module, tcp_opts) do
@spec init(reference, port, :ranch_tcp, module, module, :ranch_tcp.opts) :: :ok | no_return
def init(ref, socket, :ranch_tcp = transport, server_module, handler_module, tcp_opts) do
:ok = :ranch.accept_ack(ref)
{recv_timeout, tcp_opts} = Keyword.pop(tcp_opts, :recv_timeout, @default_timeout)
@ -50,7 +57,7 @@ defmodule Thrift.Binary.Framed.ProtocolHandler do
end
end
def handle_thrift_message({:ok, {:call, sequence_id, name, args_binary}}, server_module, handler_module) do
defp handle_thrift_message({:ok, {:call, sequence_id, name, args_binary}}, server_module, handler_module) do
case server_module.handle_thrift(name, args_binary, handler_module) do
{:reply, serialized_reply} ->
message = Protocol.Binary.serialize(:message_begin, {:reply, sequence_id, name})
@ -71,12 +78,12 @@ defmodule Thrift.Binary.Framed.ProtocolHandler do
end
def handle_thrift_message({:ok, {:oneway, _seq_id, name, args_binary}}, server_module, handler_module) do
defp handle_thrift_message({:ok, {:oneway, _seq_id, name, args_binary}}, server_module, handler_module) do
spawn(server_module, :handle_thrift, [name, args_binary, handler_module])
{:ok, :reply, <<0>>}
end
def handle_thrift_message({:error, msg} = err, _, _) do
defp handle_thrift_message({:error, msg} = err, _, _) do
Logger.warn("Could not decode Thrift message: #{inspect msg}")
err
end

View File

@ -1,4 +1,5 @@
defmodule Thrift.Mixfile do
@moduledoc false
use Mix.Project
@description """
@ -40,7 +41,7 @@ defmodule Thrift.Mixfile do
package: package(),
# Dialyzer
dialyzer: [plt_add_deps: :transitive, plt_add_apps: [:ex_unit, :mix]],
dialyzer: [plt_add_deps: :transitive, plt_add_apps: [:ex_unit, :mix, :public_key, :ssl]],
# Docs
name: "Thrift",