From 132d6fae4a8686f5cdaa8f86b7972f02b17b02e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 22 May 2018 14:21:01 +0200 Subject: [PATCH] p2p: Only use reset on streams MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Ɓukasz Magiera --- core/commands/p2p.go | 2 +- p2p/stream.go | 24 ++++-------------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/core/commands/p2p.go b/core/commands/p2p.go index edf90c891..917658c8e 100644 --- a/core/commands/p2p.go +++ b/core/commands/p2p.go @@ -386,7 +386,7 @@ var p2pStreamCloseCmd = &cmds.Command{ if !closeAll && handlerID != stream.Id { continue } - stream.Close() + stream.Reset() if !closeAll { break } diff --git a/p2p/stream.go b/p2p/stream.go index 0dc936a63..d9796e28b 100644 --- a/p2p/stream.go +++ b/p2p/stream.go @@ -27,14 +27,6 @@ type Stream struct { Registry *StreamRegistry } -// Close closes stream endpoints and deregisters it -func (s *Stream) Close() error { - s.Local.Close() - s.Remote.Close() - s.Registry.Deregister(s.Id) - return nil -} - // Reset closes stream endpoints and deregisters it func (s *Stream) Reset() error { s.Local.Close() @@ -45,21 +37,13 @@ func (s *Stream) Reset() error { func (s *Stream) startStreaming() { go func() { - _, err := io.Copy(s.Local, s.Remote) - if err != nil { - s.Reset() - } else { - s.Close() - } + io.Copy(s.Local, s.Remote) + s.Reset() }() go func() { - _, err := io.Copy(s.Remote, s.Local) - if err != nil { - s.Reset() - } else { - s.Close() - } + io.Copy(s.Remote, s.Local) + s.Reset() }() }