File 0777-kernel-Improve-socket-info-formating.patch of Package erlang
From 2bdd7b1eab615644b1583f21668622608a448c9e Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Wed, 4 Sep 2019 14:26:17 +0200
Subject: [PATCH] [kernel] Improve socket info formating
The info produced by the inet:info function has been
made a bit more informative.
OTP-16043
---
lib/kernel/src/inet.erl | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/lib/kernel/src/inet.erl b/lib/kernel/src/inet.erl
index 24aff83fbd..d91a27c769 100644
--- a/lib/kernel/src/inet.erl
+++ b/lib/kernel/src/inet.erl
@@ -1621,21 +1621,47 @@ info(S, F, Proto) ->
end.
%% Possible flags: (sorted)
%% [accepting,bound,busy,connected,connecting,listen,listening,open]
-%%
+%% Actually, we no longer gets listening...
fmt_status(Flags) ->
case lists:sort(Flags) of
[accepting | _] -> "ACCEPTING";
- [bound,busy,connected|_] -> "CONNECTED*";
- [bound,connected|_] -> "CONNECTED";
+ [bound,busy,connected|_] -> "CONNECTED(BB)";
+ [bound,connected|_] -> "CONNECTED(B)";
[bound,listen,listening | _] -> "LISTENING";
[bound,listen | _] -> "LISTEN";
[bound,connecting | _] -> "CONNECTING";
[bound,open] -> "BOUND";
+ [connected,open] -> "CONNECTED(O)";
[open] -> "IDLE";
[] -> "CLOSED";
- _ -> "????"
+ Sorted -> fmt_status2(Sorted)
end.
+fmt_status2([H]) ->
+ fmt_status3(H);
+fmt_status2([H|T]) ->
+ fmt_status3(H) ++ ":" ++ fmt_status2(T).
+
+fmt_status3(accepting) ->
+ "A";
+fmt_status3(bound) ->
+ "BD";
+fmt_status3(busy) ->
+ "BY";
+fmt_status3(connected) ->
+ "CD";
+fmt_status3(connecting) ->
+ "CG";
+fmt_status3(listen) ->
+ "LN";
+fmt_status3(listening) ->
+ "LG";
+fmt_status3(open) ->
+ "O";
+fmt_status3(X) when is_atom(X) ->
+ string:to_upper(atom_to_list(X)).
+
+
fmt_addr({error,enotconn}, _) -> "*:*";
fmt_addr({error,_}, _) -> " ";
fmt_addr({ok,Addr}, Proto) ->
--
2.16.4