1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-02-11 18:55:50 -05:00

merge http.Connection into net.Connection

This commit is contained in:
Darien Raymond
2018-04-20 21:30:58 +02:00
parent a7103481d5
commit d7aeb51904
6 changed files with 43 additions and 74 deletions

View File

@@ -48,15 +48,23 @@ func ConnectionOutputMulti(reader buf.Reader) ConnectionOption {
}
}
func ConnectionOnClose(s *signal.Notifier) ConnectionOption {
func ConnectionOnClose(n io.Closer) ConnectionOption {
return func(c *connection) {
c.onClose = s
c.onClose = n
}
}
func NewConnection(opts ...ConnectionOption) net.Conn {
c := &connection{
done: signal.NewDone(),
local: &net.TCPAddr{
IP: []byte{0, 0, 0, 0},
Port: 0,
},
remote: &net.TCPAddr{
IP: []byte{0, 0, 0, 0},
Port: 0,
},
}
for _, opt := range opts {
@@ -70,7 +78,7 @@ type connection struct {
reader *buf.BufferedReader
writer buf.Writer
done *signal.Done
onClose *signal.Notifier
onClose io.Closer
local Addr
remote Addr
}
@@ -110,7 +118,7 @@ func (c *connection) Close() error {
common.Close(c.reader)
common.Close(c.writer)
if c.onClose != nil {
c.onClose.Signal()
return c.onClose.Close()
}
return nil