Skip to content

Commit

Permalink
Minor specs/... fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hrefhref committed May 14, 2020
1 parent 911a9ea commit 7e8659d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
4 changes: 3 additions & 1 deletion lib/gen_magic/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ defmodule GenMagic.Helpers do

alias GenMagic.Result
alias GenMagic.Server
@spec perform_once(Path.t(), [Server.option()]) :: {:ok, Result.t()} | {:error, term()}

@spec perform_once(Path.t() | {:bytes, binary}, [Server.option()]) ::
{:ok, Result.t()} | {:error, term()}

@doc """
Runs a one-shot process without supervision.
Expand Down
19 changes: 8 additions & 11 deletions lib/gen_magic/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ defmodule GenMagic.Server do

@spec child_spec([option()]) :: Supervisor.child_spec()
@spec start_link([option()]) :: :gen_statem.start_ret()
@spec perform(t(), Path.t(), timeout()) :: {:ok, Result.t()} | {:error, term() | String.t()}
@spec perform(t(), Path.t() | {:bytes, binary()}, timeout()) ::
{:ok, Result.t()} | {:error, term() | String.t()}
@spec status(t(), timeout()) :: {:ok, Status.t()} | {:error, term()}
@spec stop(t(), term(), timeout()) :: :ok

Expand Down Expand Up @@ -185,11 +186,9 @@ defmodule GenMagic.Server do
end

@doc false
def starting(:info, {port, {:data, binary}}, %{port: port} = data) do
case :erlang.binary_to_term(binary) do
:ready ->
{:next_state, :available, data}
end
@ready :erlang.term_to_binary(:ready)
def starting(:info, {port, {:data, @ready}}, %{port: port} = data) do
{:next_state, :available, data}
end

def starting(:info, {port, {:exit_status, code}}, %{port: port} = data) do
Expand All @@ -198,6 +197,7 @@ defmodule GenMagic.Server do
1 -> :no_database
2 -> :no_argument
3 -> :missing_database
code -> {:unexpected_error, code}
end

{:stop, {:error, error}, data}
Expand Down Expand Up @@ -243,12 +243,10 @@ defmodule GenMagic.Server do
end

@doc false
def processing(:info, {port, {:data, response}}, %{port: port} = data) do
{_, from, _} = data.request
data = %{data | request: nil}
def processing(:info, {port, {:data, response}}, %{port: port, request: {_, from, _}} = data) do
response = {:reply, from, handle_response(response)}
next_state = (data.cycles >= data.recycle_threshold && :recycling) || :available
{:next_state, next_state, data, [response, :hibernate]}
{:next_state, next_state, %{data | request: nil}, [response, :hibernate]}
end

@doc false
Expand Down Expand Up @@ -279,7 +277,6 @@ defmodule GenMagic.Server do
@errnos %{
2 => :enoent,
13 => :eaccess,
21 => :eisdir,
20 => :enotdir,
12 => :enomem,
24 => :emfile,
Expand Down
3 changes: 1 addition & 2 deletions src/apprentice.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ int process_command(uint16_t len, byte *buf) {
return 1;
}

// Empty the buffer.
write_cmd(result.buff, result.index);

if (ei_x_free(&result) != 0) {
Expand Down Expand Up @@ -406,7 +405,7 @@ size_t read_cmd(byte *buf) {

// Buffer isn't large enough: just return possible len, without reading.
// Up to the caller of verifying the size again and return an error.
// buf left unchanged.
// buf left unchanged, stdin emptied of X bytes.
if (len16 > COMMAND_LEN) {
fdseek(len16);
return len16;
Expand Down

0 comments on commit 7e8659d

Please sign in to comment.