Skip to content

Commit

Permalink
refactor: delete stale code
Browse files Browse the repository at this point in the history
  • Loading branch information
zmstone committed Oct 4, 2024
1 parent 49d1aa9 commit c2924be
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions src/ehttpc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
pool :: term(),
id :: pos_integer(),
client :: pid() | ?undef,
%% no longer in use since 0.4.12 (changed to gun:start_link)
mref :: reference() | ?undef,
host :: inet:hostname() | inet:ip_address(),
port :: inet:port_number(),
enable_pipelining :: boolean() | non_neg_integer(),
Expand Down Expand Up @@ -205,7 +203,6 @@ init([Pool, Id, Opts0]) ->
pool = Pool,
id = Id,
client = ?undef,
mref = ?undef,
host = proplists:get_value(host, Opts),
port = proplists:get_value(port, Opts),
enable_pipelining = proplists:get_value(enable_pipelining, Opts, false),
Expand Down Expand Up @@ -322,12 +319,6 @@ do_handle_info(
log(warning, #{msg => "http_connection_down", reason => Reason}, State),
NewState = handle_gun_down(State, KilledStreams, Reason),
NewState;
do_handle_info(
{'DOWN', MRef, process, Client, Reason},
State = #state{mref = MRef, client = Client}
) ->
%% stale code for appup since 0.4.12
handle_client_down(State, Reason);
do_handle_info({'EXIT', Client, Reason}, State = #state{client = Client}) ->
handle_client_down(State, Reason);
do_handle_info(Info, State) ->
Expand Down Expand Up @@ -378,7 +369,6 @@ handle_client_down(#state{requests = Requests0} = State, Reason) ->
Requests = reply_error_for_sent_reqs(Requests0, Reason),
State#state{
requests = Requests,
mref = ?undef,
client = ?undef,
gun_state = down
}.
Expand Down Expand Up @@ -805,10 +795,10 @@ shoot(
Req = ?SENT_REQ(ReplyTo, ExpireAt, ?undef),
{noreply, State#state{requests = put_sent_req(StreamRef, Req, Requests)}}.

do_after_gun_up(State0 = #state{client = Client, mref = MRef}, ExpireAt, Fun) ->
do_after_gun_up(State0 = #state{client = Client}, ExpireAt, Fun) ->
Timeout = timeout(ExpireAt),
%% wait for the http client to be ready
{Res, State} = gun_await_up(Client, ExpireAt, Timeout, MRef, State0),
{Res, State} = gun_await_up(Client, ExpireAt, Timeout, State0),
case Res of
{ok, _} ->
Fun(State);
Expand All @@ -821,20 +811,13 @@ do_after_gun_up(State0 = #state{client = Client, mref = MRef}, ExpireAt, Fun) ->
%% of the error response.
{reply, {error, Error}, State};
{error, Reason} ->
case is_reference(MRef) of
true ->
%% stale code for appup since 0.4.12
erlang:demonitor(MRef, [flush]);
false ->
ok
end,
{reply, {error, Reason}, State#state{client = ?undef, mref = ?undef}}
{reply, {error, Reason}, State#state{client = ?undef}}
end.

%% This is a copy of gun:wait_up/3
%% with the '$gen_call' clause added so the calls in the mail box
%% are collected into the queue in time
gun_await_up(Pid, ExpireAt, Timeout, MRef, State0) ->
gun_await_up(Pid, ExpireAt, Timeout, State0) ->
receive
{gun_up, Pid, Protocol} ->
case State0#state.proxy of
Expand All @@ -844,12 +827,6 @@ gun_await_up(Pid, ExpireAt, Timeout, MRef, State0) ->
#{} = ProxyOpts ->
gun_connect_proxy(Pid, ExpireAt, Timeout, Protocol, ProxyOpts, State0)
end;
{'DOWN', MRef, process, Pid, {shutdown, Reason}} ->
%% stale code for appup since 0.4.12
{{error, Reason}, State0};
{'DOWN', MRef, process, Pid, Reason} ->
%% stale code for appup since 0.4.12
{{error, Reason}, State0};
{'EXIT', Pid, {shutdown, Reason}} ->
{{error, Reason}, State0};
{'EXIT', Pid, Reason} ->
Expand All @@ -859,12 +836,12 @@ gun_await_up(Pid, ExpireAt, Timeout, MRef, State0) ->
State = enqueue_req(ResultCallback, Req, State0),
%% keep waiting
NewTimeout = timeout(ExpireAt),
gun_await_up(Pid, ExpireAt, NewTimeout, MRef, State);
gun_await_up(Pid, ExpireAt, NewTimeout, State);
?GEN_CALL_REQ(From, Call) ->
State = enqueue_req(From, Call, State0),
%% keep waiting
NewTimeout = timeout(ExpireAt),
gun_await_up(Pid, ExpireAt, NewTimeout, MRef, State)
gun_await_up(Pid, ExpireAt, NewTimeout, State)
after Timeout ->
{{error, connect_timeout}, State0}
end.
Expand Down

0 comments on commit c2924be

Please sign in to comment.