summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicael Karlberg <bmk@erlang.org>2021-03-19 19:23:47 +0100
committerMicael Karlberg <bmk@erlang.org>2021-03-19 19:23:47 +0100
commit0f80e9d331a121bb044fe821eeb571dab071cc95 (patch)
treeb95804d59e3f5ca29d8f8ee6fa3df40b09c0a04d
parent48be374a8bd3295a9fd5e3c0e1a4f6ff3de7f20c (diff)
downloaderlang-0f80e9d331a121bb044fe821eeb571dab071cc95.tar.gz
[kernel] Renamed socket owner key in inet:info/1
The key for 'socket owner' in the info map returned by inet:info/1 is now named 'owner' in both cases (both if the socket is a port or if its a gen-tcp-socket socket). OTP-17156 (OTP-17203)
-rw-r--r--lib/kernel/src/inet.erl15
-rw-r--r--lib/kernel/test/gen_tcp_misc_SUITE.erl30
2 files changed, 28 insertions, 17 deletions
diff --git a/lib/kernel/src/inet.erl b/lib/kernel/src/inet.erl
index 206777cd2b..4af31b86cc 100644
--- a/lib/kernel/src/inet.erl
+++ b/lib/kernel/src/inet.erl
@@ -631,10 +631,11 @@ info(Socket) ->
states => States}.
port_info(P) when is_port(P) ->
- PI = port_info(erlang:port_info(P),
- [connected, links, input, output]) ++
+ PI0 = port_info(erlang:port_info(P),
+ [connected, links, input, output]) ++
[erlang:port_info(P, memory),
erlang:port_info(P, monitors)],
+ PI = pi_replace([{connected, owner}], PI0),
maps:from_list(PI);
port_info(_) ->
#{}.
@@ -648,6 +649,16 @@ port_info(PI, [Item | Items], Acc) ->
Val = proplists:get_value(Item, PI),
port_info(PI, Items, [{Item, Val} | Acc]).
+pi_replace([], Items) ->
+ Items;
+pi_replace([{Key1, Key2}|Keys], Items) ->
+ case lists:keysearch(Key1, 1, Items) of
+ {value, {Key1, Value}} ->
+ Items2 = lists:keyreplace(Key1, 1, Items, {Key2, Value}),
+ pi_replace(Keys, Items2);
+ false ->
+ pi_replace(Keys, Items)
+ end.
-spec ip(Ip :: ip_address() | string() | atom()) ->
{'ok', ip_address()} | {'error', posix()}.
diff --git a/lib/kernel/test/gen_tcp_misc_SUITE.erl b/lib/kernel/test/gen_tcp_misc_SUITE.erl
index 03a97782c6..cb4a7aa995 100644
--- a/lib/kernel/test/gen_tcp_misc_SUITE.erl
+++ b/lib/kernel/test/gen_tcp_misc_SUITE.erl
@@ -4096,21 +4096,21 @@ validate_acceptor_state(LS, ExpStates, ExpNotStates) when is_port(LS) ->
validate_acceptor_state(LS, ExpNumAcc, ExpState, ExpNotState) ->
case inet:info(LS) of
- #{num_acceptors := ExpNumAcc, rstate := State} ->
+ #{num_acceptors := ExpNumAcc, rstates := States} ->
?P("try validate state when: "
"~n Expected State: ~p"
"~n Expected Not State: ~p"
- "~n RState: ~p", [ExpState, ExpNotState, State]),
+ "~n RStates: ~p", [ExpState, ExpNotState, States]),
- %% State *shall* contain ExpState => State1 =/= State
- State1 = State -- ExpState,
+ %% States *shall* contain ExpState => States1 =/= States
+ States1 = States -- ExpState,
- %% State shall *not* contain ExpNotState => State2 =:= State
- State2 = State -- ExpNotState,
+ %% States shall *not* contain ExpNotState => States2 =:= States
+ States2 = States -- ExpNotState,
if
- (State1 =/= State) andalso
- (State2 =:= State) ->
+ (States1 =/= States) andalso
+ (States2 =:= States) ->
?P("validated: "
"~n Expected States: ~p"
"~n Expected Not States: ~p",
@@ -4120,20 +4120,20 @@ validate_acceptor_state(LS, ExpNumAcc, ExpState, ExpNotState) ->
?P("invalid states: "
"~n Expected State: ~p"
"~n Expected Not State: ~p"
- "~n State: ~p",
- [ExpState, ExpNotState, State]),
+ "~n States: ~p",
+ [ExpState, ExpNotState, States]),
ct:fail("Invalid state(s)")
end;
- #{num_acceptors := NumAcc, rstate := RState, wstate := WState} ->
+ #{num_acceptors := NumAcc, rstates := RStates, wstates := WStates} ->
?P("invalid state: "
"~n Expected Num Acceptors: ~w"
"~n Num Acceptors: ~w"
"~n Expected State: ~p"
"~n Expected Not State: ~p"
- "~n RState: ~p"
- "~n WState: ~p",
- [ExpNumAcc, NumAcc, ExpState, RState, WState]),
+ "~n RStates: ~p"
+ "~n WStates: ~p",
+ [ExpNumAcc, NumAcc, ExpState, RStates, WStates]),
ct:fail("Invalid state");
InvalidInfo ->
@@ -4142,7 +4142,7 @@ validate_acceptor_state(LS, ExpNumAcc, ExpState, ExpNotState) ->
"~n Expected State: ~p"
"~n Expected Not State: ~p"
"~n Invalid Info: ~p",
- [ExpNumAcc, ExpState, InvalidInfo]),
+ [ExpNumAcc, ExpNumAcc, ExpState, InvalidInfo]),
ct:fail("Invalid state")
end.