Add read deadline implementation

This commit is contained in:
世界 2023-04-08 14:41:53 +08:00
parent 17988ac0d3
commit 5c830455eb
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
8 changed files with 25 additions and 19 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/buf"
"github.com/sagernet/sing/common/bufio"
"github.com/sagernet/sing/common/bufio/deadline"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/rw"
@ -94,15 +95,15 @@ func (m *Method) DialConn(conn net.Conn, destination M.Socksaddr) (net.Conn, err
Method: m,
destination: destination,
}
return shadowsocksConn, shadowsocksConn.writeRequest(nil)
return deadline.NewConn(shadowsocksConn), shadowsocksConn.writeRequest(nil)
}
func (m *Method) DialEarlyConn(conn net.Conn, destination M.Socksaddr) net.Conn {
return &clientConn{
return deadline.NewConn(&clientConn{
Conn: conn,
Method: m,
destination: destination,
}
})
}
func (m *Method) DialPacketConn(conn net.Conn) N.NetPacketConn {

View file

@ -14,6 +14,7 @@ import (
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/buf"
"github.com/sagernet/sing/common/bufio"
"github.com/sagernet/sing/common/bufio/deadline"
E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
@ -125,11 +126,11 @@ func (s *Service) newConnection(ctx context.Context, conn net.Conn, metadata M.M
metadata.Protocol = "shadowsocks"
metadata.Destination = destination
return s.handler.NewConnection(ctx, &serverConn{
return s.handler.NewConnection(ctx, deadline.NewConn(&serverConn{
Service: s,
Conn: conn,
reader: reader,
}, metadata)
}), metadata)
}
func (s *Service) NewError(ctx context.Context, err error) {