| 6 | |
| 7 | namespace WinSys { |
| 8 | class ActiveConnectionTracker { |
| 9 | public: |
| 10 | int EnumConnections(); |
| 11 | void Reset(); |
| 12 | |
| 13 | void SetTrackingFlags(ConnectionType type); |
| 14 | ConnectionType GetTrackingFlags() const; |
| 15 | |
| 16 | using ConnectionMap = std::unordered_map<Connection, std::shared_ptr<Connection>>; |
| 17 | using ConnectionVec = std::vector<std::shared_ptr<Connection>>; |
| 18 | |
| 19 | const ConnectionVec& GetConnections() const; |
| 20 | const ConnectionVec& GetNewConnections() const; |
| 21 | const ConnectionVec& GetCloseConnections() const; |
| 22 | |
| 23 | private: |
| 24 | void InitTcp4Connection(Connection* conn, const MIB_TCPROW_OWNER_MODULE& item) const; |
| 25 | void InitTcp6Connection(Connection* conn, const MIB_TCP6ROW_OWNER_MODULE& item) const; |
| 26 | void InitUdp4Connection(Connection* conn, const MIB_UDPROW_OWNER_MODULE& item) const; |
| 27 | void InitUdp6Connection(Connection* conn, const MIB_UDP6ROW_OWNER_MODULE& item) const; |
| 28 | |
| 29 | void AddTcp4Connections(PMIB_TCPTABLE_OWNER_MODULE table, ConnectionMap& map, ConnectionVec& local, bool first); |
| 30 | void AddTcp6Connections(PMIB_TCP6TABLE_OWNER_MODULE table, ConnectionMap& map, ConnectionVec& local, bool first); |
| 31 | void AddUdp4Connections(PMIB_UDPTABLE_OWNER_MODULE table, ConnectionMap& map, ConnectionVec& local, bool first); |
| 32 | void AddUdp6Connections(PMIB_UDP6TABLE_OWNER_MODULE table, ConnectionMap& map, ConnectionVec& local, bool first); |
| 33 | |
| 34 | ConnectionType _trackedConnections{ ConnectionType::All }; |
| 35 | ConnectionVec _connections; |
| 36 | ConnectionVec _newConnections; |
| 37 | ConnectionVec _closedConnections; |
| 38 | ConnectionMap _connectionMap; |
| 39 | inline static thread_local BYTE _buffer[1 << 10]; |
| 40 | }; |
| 41 | } |
| 42 | |
| 43 |
nothing calls this directly
no outgoing calls
no test coverage detected