github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/bufio/bind_wait.go (about)

     1  package bufio
     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  var _ N.ReadWaiter = (*BindPacketReadWaiter)(nil)
    10  
    11  type BindPacketReadWaiter struct {
    12  	readWaiter N.PacketReadWaiter
    13  }
    14  
    15  func (w *BindPacketReadWaiter) InitializeReadWaiter(options N.ReadWaitOptions) (needCopy bool) {
    16  	return w.readWaiter.InitializeReadWaiter(options)
    17  }
    18  
    19  func (w *BindPacketReadWaiter) WaitReadBuffer() (buffer *buf.Buffer, err error) {
    20  	buffer, _, err = w.readWaiter.WaitReadPacket()
    21  	return
    22  }
    23  
    24  var _ N.PacketReadWaiter = (*UnbindPacketReadWaiter)(nil)
    25  
    26  type UnbindPacketReadWaiter struct {
    27  	readWaiter N.ReadWaiter
    28  	addr       M.Socksaddr
    29  }
    30  
    31  func (w *UnbindPacketReadWaiter) InitializeReadWaiter(options N.ReadWaitOptions) (needCopy bool) {
    32  	return w.readWaiter.InitializeReadWaiter(options)
    33  }
    34  
    35  func (w *UnbindPacketReadWaiter) WaitReadPacket() (buffer *buf.Buffer, destination M.Socksaddr, err error) {
    36  	buffer, err = w.readWaiter.WaitReadBuffer()
    37  	if err != nil {
    38  		return
    39  	}
    40  	destination = w.addr
    41  	return
    42  }