Skip to content

Commit

Permalink
Don't require conn in HandleAssociation().
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Jan 8, 2025
1 parent 19fb5f7 commit c656b36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion service/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 6 additions & 2 deletions service/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit c656b36

Please sign in to comment.