mirror of https://github.com/v2ray/v2ray-core
release buffer
parent
0bf5f3e531
commit
1ee9450dfc
|
@ -82,7 +82,7 @@ func (w *tcpWorker) Port() v2net.Port {
|
||||||
|
|
||||||
type udpConn struct {
|
type udpConn struct {
|
||||||
lastActivityTime int64 // in seconds
|
lastActivityTime int64 // in seconds
|
||||||
input chan []byte
|
input chan *buf.Buffer
|
||||||
output func([]byte) (int, error)
|
output func([]byte) (int, error)
|
||||||
remote net.Addr
|
remote net.Addr
|
||||||
local net.Addr
|
local net.Addr
|
||||||
|
@ -98,8 +98,9 @@ func (c *udpConn) Read(buf []byte) (int, error) {
|
||||||
if !open {
|
if !open {
|
||||||
return 0, io.EOF
|
return 0, io.EOF
|
||||||
}
|
}
|
||||||
|
defer in.Release()
|
||||||
c.updateActivity()
|
c.updateActivity()
|
||||||
return copy(buf, in), nil
|
return copy(buf, in.Bytes()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *udpConn) Write(buf []byte) (int, error) {
|
func (c *udpConn) Write(buf []byte) (int, error) {
|
||||||
|
@ -164,7 +165,7 @@ func (w *udpWorker) getConnection(src v2net.Destination) (*udpConn, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := &udpConn{
|
conn := &udpConn{
|
||||||
input: make(chan []byte, 32),
|
input: make(chan *buf.Buffer, 32),
|
||||||
output: func(b []byte) (int, error) {
|
output: func(b []byte) (int, error) {
|
||||||
return w.hub.WriteTo(b, src)
|
return w.hub.WriteTo(b, src)
|
||||||
},
|
},
|
||||||
|
@ -185,7 +186,11 @@ func (w *udpWorker) getConnection(src v2net.Destination) (*udpConn, bool) {
|
||||||
|
|
||||||
func (w *udpWorker) callback(b *buf.Buffer, source v2net.Destination, originalDest v2net.Destination) {
|
func (w *udpWorker) callback(b *buf.Buffer, source v2net.Destination, originalDest v2net.Destination) {
|
||||||
conn, existing := w.getConnection(source)
|
conn, existing := w.getConnection(source)
|
||||||
conn.input <- b.Bytes()
|
select {
|
||||||
|
case conn.input <- b:
|
||||||
|
default:
|
||||||
|
b.Release()
|
||||||
|
}
|
||||||
|
|
||||||
if !existing {
|
if !existing {
|
||||||
go func() {
|
go func() {
|
||||||
|
|
Loading…
Reference in New Issue