feat(client,mux): Improve stream readiness detection and add safe buffer access

This commit is contained in:
zarazaex69
2026-04-09 18:18:14 +03:00
parent 5bee796a30
commit 533b0dabdb
2 changed files with 10 additions and 3 deletions

View File

@@ -218,10 +218,11 @@ func (c *Client) handleSOCKS5(conn net.Conn) {
defer timeout.Stop()
go func() {
for i := 0; i < 100; i++ {
for i := 0; i < 200; i++ {
time.Sleep(50 * time.Millisecond)
data := c.mux.ReadStream(sid)
if len(data) > 0 {
stream := c.mux.GetStream(sid)
if stream != nil && len(stream.RecvBuf()) > 0 {
connected <- true
return
}

View File

@@ -17,6 +17,12 @@ type Stream struct {
mu sync.Mutex
}
func (s *Stream) RecvBuf() []byte {
s.mu.Lock()
defer s.mu.Unlock()
return s.recvBuf
}
type Multiplexer struct {
streams map[uint16]*Stream
nextID uint16