mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-20 01:00:56 +00:00
add peek mutex
This commit is contained in:
parent
374c58ae76
commit
f6f94d8de8
1 changed files with 6 additions and 0 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/metacubex/mihomo/adapter/inbound"
|
||||
|
@ -28,6 +29,7 @@ func HandleConn(c net.Conn, tunnel C.Tunnel, cache *lru.LruCache[string, bool],
|
|||
defer client.CloseIdleConnections()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
peekMutex := sync.Mutex{}
|
||||
|
||||
conn := N.NewBufferedConn(c)
|
||||
|
||||
|
@ -35,7 +37,9 @@ func HandleConn(c net.Conn, tunnel C.Tunnel, cache *lru.LruCache[string, bool],
|
|||
trusted := cache == nil // disable authenticate if lru is nil
|
||||
|
||||
for keepAlive {
|
||||
peekMutex.Lock()
|
||||
request, err := ReadRequest(conn.Reader())
|
||||
peekMutex.Unlock()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
@ -87,6 +91,8 @@ func HandleConn(c net.Conn, tunnel C.Tunnel, cache *lru.LruCache[string, bool],
|
|||
|
||||
startBackgroundRead := func() {
|
||||
go func() {
|
||||
peekMutex.Lock()
|
||||
defer peekMutex.Unlock()
|
||||
_, err := conn.Peek(1)
|
||||
if err != nil {
|
||||
cancel()
|
||||
|
|
Loading…
Add table
Reference in a new issue