github.com/sagernet/sing-shadowsocks2@v0.2.0/cipher/method_none_wait.go (about) 1 package cipher 2 3 import ( 4 "github.com/sagernet/sing/common/buf" 5 "github.com/sagernet/sing/common/bufio" 6 M "github.com/sagernet/sing/common/metadata" 7 N "github.com/sagernet/sing/common/network" 8 ) 9 10 var _ N.PacketReadWaitCreator = (*nonePacketConn)(nil) 11 12 func (c *nonePacketConn) CreateReadWaiter() (N.PacketReadWaiter, bool) { 13 readWaiter, isReadWaiter := bufio.CreateReadWaiter(c.conn) 14 if !isReadWaiter { 15 return nil, false 16 } 17 return &nonePacketReadWaiter{readWaiter}, true 18 } 19 20 var _ N.PacketReadWaiter = (*nonePacketReadWaiter)(nil) 21 22 type nonePacketReadWaiter struct { 23 readWaiter N.ReadWaiter 24 } 25 26 func (w *nonePacketReadWaiter) InitializeReadWaiter(options N.ReadWaitOptions) (needCopy bool) { 27 return w.readWaiter.InitializeReadWaiter(options) 28 } 29 30 func (w *nonePacketReadWaiter) WaitReadPacket() (buffer *buf.Buffer, destination M.Socksaddr, err error) { 31 buffer, err = w.readWaiter.WaitReadBuffer() 32 if err != nil { 33 return 34 } 35 destination, err = M.SocksaddrSerializer.ReadAddrPort(buffer) 36 if err != nil { 37 buffer.Release() 38 return nil, M.Socksaddr{}, err 39 } 40 return 41 }