mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
use local buffer in UDP hub
This commit is contained in:
parent
d3f323e24b
commit
5b58066345
@ -18,6 +18,7 @@ type UDPHub struct {
|
|||||||
conn *net.UDPConn
|
conn *net.UDPConn
|
||||||
option ListenOption
|
option ListenOption
|
||||||
accepting bool
|
accepting bool
|
||||||
|
pool *alloc.BufferPool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListenOption struct {
|
type ListenOption struct {
|
||||||
@ -48,6 +49,7 @@ func ListenUDP(address v2net.Address, port v2net.Port, option ListenOption) (*UD
|
|||||||
hub := &UDPHub{
|
hub := &UDPHub{
|
||||||
conn: udpConn,
|
conn: udpConn,
|
||||||
option: option,
|
option: option,
|
||||||
|
pool: alloc.NewBufferPool(2048, 64),
|
||||||
}
|
}
|
||||||
go hub.start()
|
go hub.start()
|
||||||
return hub, nil
|
return hub, nil
|
||||||
@ -75,7 +77,7 @@ func (this *UDPHub) start() {
|
|||||||
|
|
||||||
oobBytes := make([]byte, 256)
|
oobBytes := make([]byte, 256)
|
||||||
for this.Running() {
|
for this.Running() {
|
||||||
buffer := alloc.NewBuffer()
|
buffer := this.pool.Allocate()
|
||||||
nBytes, noob, _, addr, err := ReadUDPMsg(this.conn, buffer.Value, oobBytes)
|
nBytes, noob, _, addr, err := ReadUDPMsg(this.conn, buffer.Value, oobBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("UDP|Hub: Failed to read UDP msg: ", err)
|
log.Info("UDP|Hub: Failed to read UDP msg: ", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user