From 9f8206d7012ad0c1529a0dba22f58fe3feeda08c Mon Sep 17 00:00:00 2001 From: Wolfgang Welz <welzwo@gmail.com> Date: Thu, 18 Jun 2020 13:45:21 +0200 Subject: [PATCH] close on write --- plugins/analysis/client/plugin.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/analysis/client/plugin.go b/plugins/analysis/client/plugin.go index 24b2e1eb..3bb144f3 100644 --- a/plugins/analysis/client/plugin.go +++ b/plugins/analysis/client/plugin.go @@ -13,6 +13,7 @@ import ( "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/hive.go/netutil" "github.com/iotaledger/hive.go/network" "github.com/iotaledger/hive.go/node" flag "github.com/spf13/pflag" @@ -116,6 +117,7 @@ func (c *connector) new() { } } +// Close closes the current connection. func (c *connector) Close() (err error) { c.mu.Lock() defer c.mu.Unlock() @@ -127,13 +129,17 @@ func (c *connector) Close() (err error) { } func (c *connector) Write(b []byte) (int, error) { - // TODO: check that start was called - // TODO: check that Stop was not called c.mu.Lock() defer c.mu.Unlock() if c.conn == nil { return 0, errors.New("no connection established") } - return c.conn.Write(b) + n, err := c.conn.Write(b) + // TODO: should the closing rather only happen outside? + // TODO: is the IsTemporaryError useful here? + if err != nil && !netutil.IsTemporaryError(err) { + c.conn.Close() + } + return n, err } -- GitLab