p2p: Only use reset on streams
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
May 22, 2018 at 14:21 UTC
132d6fae4a8686f5cdaa8f86b7972f02b17b02e7
2 files changed
+5
-21
core/commands/p2p.go
+1
-1
@@ -386,7 +386,7 @@ var p2pStreamCloseCmd = &cmds.Command{
386
if !closeAll && handlerID != stream.Id {
387
continue
388
}
389
- stream.Close()
389
+ stream.Reset()
390
if !closeAll {
391
break
392
}
p2p/stream.go
+4
-20
@@ -27,14 +27,6 @@ type Stream struct {
27
Registry *StreamRegistry
28
}
29
30
-// Close closes stream endpoints and deregisters it
31
-func (s *Stream) Close() error {
32
- s.Local.Close()
33
- s.Remote.Close()
34
- s.Registry.Deregister(s.Id)
35
- return nil
36
-}
37
-
30
// Reset closes stream endpoints and deregisters it
31
func (s *Stream) Reset() error {
32
s.Local.Close()
@@ -45,21 +37,13 @@ func (s *Stream) Reset() error {
37
38
func (s *Stream) startStreaming() {
39
go func() {
48
- _, err := io.Copy(s.Local, s.Remote)
49
- if err != nil {
50
- s.Reset()
51
- } else {
52
- s.Close()
53
- }
40
+ io.Copy(s.Local, s.Remote)
41
+ s.Reset()
42
}()
43
44
go func() {
57
- _, err := io.Copy(s.Remote, s.Local)
58
- if err != nil {
59
- s.Reset()
60
- } else {
61
- s.Close()
62
- }
45
+ io.Copy(s.Remote, s.Local)
46
+ s.Reset()
47
}()
48
}
49