[#567] network/clients: Implement method to close the cached clients

Update API Go library with introduce `Client.Conn` method. Implement
`ClientCache.CloseAll` method which reads and closes connections of all
cached clients.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-31 09:43:35 +03:00 committed by Leonard Lyubich
parent 2e814941c0
commit bf92e895c0
3 changed files with 21 additions and 3 deletions

View file

@ -75,3 +75,21 @@ func (c *ClientCache) Get(netAddr *network.Address) (client.Client, error) {
return cli, nil
}
// CloseAll closes underlying connections of all cached clients.
//
// Ignores closing errors.
func (c *ClientCache) CloseAll() {
c.mu.RLock()
{
for _, cl := range c.clients {
con := cl.Conn()
if con != nil {
_ = con.Close()
}
}
}
c.mu.RUnlock()
}