提交 132d6fae 作者: Łukasz Magiera

p2p: Only use reset on streams

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 8b7bf266
...@@ -386,7 +386,7 @@ var p2pStreamCloseCmd = &cmds.Command{ ...@@ -386,7 +386,7 @@ var p2pStreamCloseCmd = &cmds.Command{
if !closeAll && handlerID != stream.Id { if !closeAll && handlerID != stream.Id {
continue continue
} }
stream.Close() stream.Reset()
if !closeAll { if !closeAll {
break break
} }
......
...@@ -27,14 +27,6 @@ type Stream struct { ...@@ -27,14 +27,6 @@ type Stream struct {
Registry *StreamRegistry 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 // Reset closes stream endpoints and deregisters it
func (s *Stream) Reset() error { func (s *Stream) Reset() error {
s.Local.Close() s.Local.Close()
...@@ -45,21 +37,13 @@ func (s *Stream) Reset() error { ...@@ -45,21 +37,13 @@ func (s *Stream) Reset() error {
func (s *Stream) startStreaming() { func (s *Stream) startStreaming() {
go func() { go func() {
_, err := io.Copy(s.Local, s.Remote) io.Copy(s.Local, s.Remote)
if err != nil { s.Reset()
s.Reset()
} else {
s.Close()
}
}() }()
go func() { go func() {
_, err := io.Copy(s.Remote, s.Local) io.Copy(s.Remote, s.Local)
if err != nil { s.Reset()
s.Reset()
} else {
s.Close()
}
}() }()
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论