File 6124-inets-review-comments-and-refactor.patch of Package erlang
From 9bc563b689f84ddb60cc033a6f31ac42e696be7c Mon Sep 17 00:00:00 2001
From: Jakub Witczak <kuba@erlang.org>
Date: Wed, 12 Apr 2023 09:50:17 +0200
Subject: [PATCH 4/4] inets: review comments and refactor
---
lib/inets/src/http_client/httpc_handler.erl | 85 ++++++++-------------
1 file changed, 30 insertions(+), 55 deletions(-)
diff --git a/lib/inets/src/http_client/httpc_handler.erl b/lib/inets/src/http_client/httpc_handler.erl
index 742c73536f..026cea9b1f 100644
--- a/lib/inets/src/http_client/httpc_handler.erl
+++ b/lib/inets/src/http_client/httpc_handler.erl
@@ -292,75 +292,36 @@ handle_info(Info, State) ->
%% Function: terminate(Reason, State) -> _ (ignored by gen_server)
%% Description: Shutdown the httpc_handler
%%--------------------------------------------------------------------
-
terminate(normal, #state{session = undefined}) ->
- ok;
-
+ ok;
%% Init error sending, no session information has been setup but
%% there is a socket that needs closing.
-terminate(normal,
- #state{session = #session{id = undefined} = Session}) ->
+terminate(normal,
+ #state{session = #session{id = undefined} = Session}) ->
close_socket(Session);
-
%% Socket closed remotely
-terminate(normal,
- #state{session = #session{socket = {remote_close, Socket},
- socket_type = SocketType,
- type = Type,
- id = Id},
- profile_name = ProfileName,
- request = Request,
- timers = Timers,
- pipeline = Pipeline,
- keep_alive = KeepAlive} = State) ->
- %% Clobber session
- (catch httpc_manager:delete_session(Id, ProfileName)),
-
- case Type of
- pipeline ->
- maybe_retry_queue(Pipeline, State);
- _ ->
- maybe_retry_queue(KeepAlive, State)
- end,
-
- %% Cancel timers
+terminate(normal, #state{session = #session{socket = {remote_close, Socket},
+ socket_type = SocketType},
+ request = Request,
+ timers = Timers} = State) ->
+ clobber_and_retry(State),
cancel_timers(Timers),
-
%% Maybe deliver answers to requests
maybe_deliver_answer(Request, State),
-
%% And, just in case, close our side (**really** overkill)
http_transport:close(SocketType, Socket);
-
-terminate(_Reason, #state{session = #session{id = Id,
- socket = Socket,
- type = Type,
+terminate(_Reason, #state{session = #session{socket = Socket,
socket_type = SocketType},
- request = undefined,
- profile_name = ProfileName,
- timers = Timers,
- pipeline = Pipeline,
- keep_alive = KeepAlive} = State) ->
-
- %% Clobber session
- (catch httpc_manager:delete_session(Id, ProfileName)),
-
- case Type of
- pipeline ->
- maybe_retry_queue(Pipeline, State);
- _ ->
- maybe_retry_queue(KeepAlive, State)
- end,
-
+ request = undefined,
+ timers = Timers} = State) ->
+ clobber_and_retry(State),
cancel_timer(Timers#timers.queue_timer, timeout_queue),
http_transport:close(SocketType, Socket);
-
-terminate(_Reason, #state{request = undefined}) ->
+terminate(_Reason, #state{request = undefined}) ->
ok;
-
-terminate(Reason, #state{request = Request} = State) ->
- NewState = maybe_send_answer(Request,
- httpc_response:error(Request, Reason),
+terminate(Reason, #state{request = Request} = State) ->
+ NewState = maybe_send_answer(Request,
+ httpc_response:error(Request, Reason),
State),
terminate(Reason, NewState#state{request = undefined}).
@@ -1735,3 +1696,17 @@ format_address({[$[|T], Port}) ->
{Address, Port};
format_address(HostPort) ->
HostPort.
+
+clobber_and_retry(#state{session = #session{id = Id,
+ type = Type},
+ profile_name = ProfileName,
+ pipeline = Pipeline,
+ keep_alive = KeepAlive} = State) ->
+ %% Clobber session
+ (catch httpc_manager:delete_session(Id, ProfileName)),
+ case Type of
+ pipeline ->
+ maybe_retry_queue(Pipeline, State);
+ _ ->
+ maybe_retry_queue(KeepAlive, State)
+ end.
--
2.35.3