upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 7a13257..4fe5f15 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -66,8 +66,12 @@ static string SockAccountingText()
66 66
67 string str = "\n sockets by where they were created\n"; 67 string str = "\n sockets by where they were created\n";
68 str += " site opened closed live close failed\n"; 68 str += " site opened closed live close failed\n";
69 long long nTotalOpened = 0, nTotalClosed = 0, nTotalFailed = 0;
69 for (int i = 0; i < SOCK_SITES; i++) 70 for (int i = 0; i < SOCK_SITES; i++)
70 { 71 {
72 nTotalOpened += nOpened[i];
73 nTotalClosed += nClosed[i];
74 nTotalFailed += nFailed[i];
71 if (nOpened[i] == 0) 75 if (nOpened[i] == 0)
72 continue; 76 continue;
73 str += strprintf(" %-24s %8lld %8lld %8lld %13lld\n", pszSockSite[i], 77 str += strprintf(" %-24s %8lld %8lld %8lld %13lld\n", pszSockSite[i],
@@ -75,6 +79,31 @@ static string SockAccountingText()
75 } 79 }
76 str += strprintf(" %-24s %8s %8lld %8s %13s\n", "closed but never tagged", 80 str += strprintf(" %-24s %8s %8lld %8s %13s\n", "closed but never tagged",
77 "-", nUntagged, "-", "-"); 81 "-", nUntagged, "-", "-");
82 str += strprintf(" %-24s %8lld %8lld %8lld %13lld\n", "TOTAL",
83 nTotalOpened, nTotalClosed, nTotalOpened - nTotalClosed, nTotalFailed);
84
85 // The live total above is what this program believes it is holding. Compare
86 // it against what the operating system attributes to the process: on
87 // Windows, `Get-NetTCPConnection | ? OwningProcess -eq <pid>`. A gap there
88 // is the leak, and the codes below say what the failed closes hit -- 10038
89 // (WSAENOTSOCK) means the handle was already gone and this close was a
90 // second one, which is a different bug from a descriptor that stayed.
91 if (nTotalFailed > 0)
92 {
93 str += " close failures by code\n";
94 for (int i = 0; i < SOCK_SITES; i++)
95 {
96 if (nFailed[i] == 0)
97 continue;
98 map<int, long long> mapErr;
99 BtfSockCloseErrors(i, mapErr);
100 string strCodes;
101 for (map<int, long long>::const_iterator mi = mapErr.begin(); mi != mapErr.end(); ++mi)
102 strCodes += strprintf("%s%d x%lld", strCodes.empty() ? "" : ", ",
103 mi->first, mi->second);
104 str += strprintf(" %-24s %s\n", pszSockSite[i], strCodes.c_str());
105 }
106 }
78 return str; 107 return str;
79} 108}
80 109