[#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:
parent
2e814941c0
commit
bf92e895c0
3 changed files with 21 additions and 3 deletions
18
pkg/network/cache/client.go
vendored
18
pkg/network/cache/client.go
vendored
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue