github.com/metacubex/mihomo@v1.18.5/common/net/packet/thread_sing.go (about)

     1  package packet
     2  
     3  import (
     4  	"github.com/sagernet/sing/common/buf"
     5  	M "github.com/sagernet/sing/common/metadata"
     6  	N "github.com/sagernet/sing/common/network"
     7  )
     8  
     9  type threadSafeSingPacketConn struct {
    10  	*threadSafePacketConn
    11  	singPacketConn SingPacketConn
    12  }
    13  
    14  var _ N.NetPacketConn = (*threadSafeSingPacketConn)(nil)
    15  
    16  func (c *threadSafeSingPacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
    17  	c.access.Lock()
    18  	defer c.access.Unlock()
    19  	return c.singPacketConn.WritePacket(buffer, destination)
    20  }
    21  
    22  func (c *threadSafeSingPacketConn) ReadPacket(buffer *buf.Buffer) (destination M.Socksaddr, err error) {
    23  	return c.singPacketConn.ReadPacket(buffer)
    24  }