mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
fixed possible memory leak for UDP stream
This commit is contained in:
parent
51c6eb4597
commit
d3b8cb8cba
2 changed files with 8 additions and 2 deletions
|
@ -5,6 +5,5 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
udpBufferSize = 8192
|
||||
streamStopListenTimeout = 1 * time.Second
|
||||
)
|
||||
|
|
|
@ -20,6 +20,7 @@ type (
|
|||
targetAddr *net.UDPAddr
|
||||
}
|
||||
UDPConn struct {
|
||||
key string
|
||||
src *net.UDPConn
|
||||
dst *net.UDPConn
|
||||
U.BidirectionalPipe
|
||||
|
@ -29,6 +30,8 @@ type (
|
|||
|
||||
var NewUDPConnMap = F.NewMap[UDPConnMap]
|
||||
|
||||
const udpBufferSize = 8192
|
||||
|
||||
func NewUDPRoute(base *StreamRoute) StreamImpl {
|
||||
return &UDPRoute{
|
||||
StreamRoute: base,
|
||||
|
@ -87,6 +90,7 @@ func (route *UDPRoute) Accept() (any, error) {
|
|||
return nil, err
|
||||
}
|
||||
conn = &UDPConn{
|
||||
key,
|
||||
srcConn,
|
||||
dstConn,
|
||||
U.NewBidirectionalPipe(route.ctx, sourceRWCloser{in, dstConn}, sourceRWCloser{in, srcConn}),
|
||||
|
@ -99,7 +103,10 @@ func (route *UDPRoute) Accept() (any, error) {
|
|||
}
|
||||
|
||||
func (route *UDPRoute) Handle(c any) error {
|
||||
return c.(*UDPConn).Start()
|
||||
conn := c.(*UDPConn)
|
||||
err := conn.Start()
|
||||
route.connMap.Delete(conn.key)
|
||||
return err
|
||||
}
|
||||
|
||||
func (route *UDPRoute) CloseListeners() {
|
||||
|
|
Loading…
Add table
Reference in a new issue