diff --git a/service/shadowsocks.go b/service/shadowsocks.go index 9137136d..23c17623 100644 --- a/service/shadowsocks.go +++ b/service/shadowsocks.go @@ -148,7 +148,7 @@ func (s *ssService) HandleAssociation(conn net.Conn) error { if err != nil { return fmt.Errorf("failed to handle association: %v", err) } - HandleAssociation(conn, assoc) + HandleAssociation(assoc) return nil } diff --git a/service/udp.go b/service/udp.go index 8cbfea6a..94f8430b 100644 --- a/service/udp.go +++ b/service/udp.go @@ -355,11 +355,11 @@ func (m *natmap) Close() error { return err } -func HandleAssociation(conn net.Conn, assoc PacketAssociation) { +func HandleAssociation(assoc PacketAssociation) { for { lazySlice := readBufPool.LazySlice() buf := lazySlice.Acquire() - n, err := conn.Read(buf) + n, err := assoc.Read(buf) if errors.Is(err, net.ErrClosed) { lazySlice.Release() return @@ -384,9 +384,13 @@ type PacketAssociation interface { // released after the packet is processed. HandlePacket(pkt []byte, lazySlice slicepool.LazySlice) + // Read reads data from the association. + Read(b []byte) (n int, err error) + // Done returns a channel that is closed when the association is closed. Done() <-chan struct{} + // Close closes the association and releases any associated resources. Close() error }