mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-07-18 13:42:29 +03:00
Add OpenVPN, TrustTunnel, Sudoku, inbound managers. Fixes
This commit is contained in:
38
common/onclose/conn.go
Normal file
38
common/onclose/conn.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package onclose
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type CloseHandlerFunc = func()
|
||||
|
||||
type Conn struct {
|
||||
net.Conn
|
||||
onClose func()
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
func NewConn(conn net.Conn, onClose func()) *Conn {
|
||||
return &Conn{Conn: conn, onClose: onClose}
|
||||
}
|
||||
|
||||
func (c *Conn) Close() error {
|
||||
c.once.Do(c.onClose)
|
||||
return c.Conn.Close()
|
||||
}
|
||||
|
||||
type PacketConn struct {
|
||||
net.PacketConn
|
||||
onClose func()
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
func NewPacketConn(conn net.PacketConn, onClose func()) *PacketConn {
|
||||
return &PacketConn{PacketConn: conn, onClose: onClose}
|
||||
}
|
||||
|
||||
func (c *PacketConn) Close() error {
|
||||
c.once.Do(c.onClose)
|
||||
return c.PacketConn.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user