1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-23 13:44:27 +08:00

p2p: Only use reset on streams

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
Łukasz Magiera
2018-05-22 14:21:01 +02:00
parent 8b7bf26664
commit 132d6fae4a
2 changed files with 5 additions and 21 deletions

View File

@ -386,7 +386,7 @@ var p2pStreamCloseCmd = &cmds.Command{
if !closeAll && handlerID != stream.Id {
continue
}
stream.Close()
stream.Reset()
if !closeAll {
break
}

View File

@ -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()
}()
}