Skip to content

Commit c656b36

Browse files
committed
Don't require conn in HandleAssociation().
1 parent 19fb5f7 commit c656b36

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

service/shadowsocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (s *ssService) HandleAssociation(conn net.Conn) error {
148148
if err != nil {
149149
return fmt.Errorf("failed to handle association: %v", err)
150150
}
151-
HandleAssociation(conn, assoc)
151+
HandleAssociation(assoc)
152152
return nil
153153
}
154154

service/udp.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,11 @@ func (m *natmap) Close() error {
355355
return err
356356
}
357357

358-
func HandleAssociation(conn net.Conn, assoc PacketAssociation) {
358+
func HandleAssociation(assoc PacketAssociation) {
359359
for {
360360
lazySlice := readBufPool.LazySlice()
361361
buf := lazySlice.Acquire()
362-
n, err := conn.Read(buf)
362+
n, err := assoc.Read(buf)
363363
if errors.Is(err, net.ErrClosed) {
364364
lazySlice.Release()
365365
return
@@ -384,9 +384,13 @@ type PacketAssociation interface {
384384
// released after the packet is processed.
385385
HandlePacket(pkt []byte, lazySlice slicepool.LazySlice)
386386

387+
// Read reads data from the association.
388+
Read(b []byte) (n int, err error)
389+
387390
// Done returns a channel that is closed when the association is closed.
388391
Done() <-chan struct{}
389392

393+
390394
// Close closes the association and releases any associated resources.
391395
Close() error
392396
}

0 commit comments

Comments
 (0)