github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/bufio/wait.go (about) 1 package bufio 2 3 import ( 4 "io" 5 6 N "github.com/sagernet/sing/common/network" 7 ) 8 9 func CreateReadWaiter(reader io.Reader) (N.ReadWaiter, bool) { 10 reader = N.UnwrapReader(reader) 11 if readWaiter, isReadWaiter := reader.(N.ReadWaiter); isReadWaiter { 12 return readWaiter, true 13 } 14 if readWaitCreator, isCreator := reader.(N.ReadWaitCreator); isCreator { 15 return readWaitCreator.CreateReadWaiter() 16 } 17 if readWaiter, created := createSyscallReadWaiter(reader); created { 18 return readWaiter, true 19 } 20 return nil, false 21 } 22 23 func CreatePacketReadWaiter(reader N.PacketReader) (N.PacketReadWaiter, bool) { 24 reader = N.UnwrapPacketReader(reader) 25 if readWaiter, isReadWaiter := reader.(N.PacketReadWaiter); isReadWaiter { 26 return readWaiter, true 27 } 28 if readWaitCreator, isCreator := reader.(N.PacketReadWaitCreator); isCreator { 29 return readWaitCreator.CreateReadWaiter() 30 } 31 if readWaiter, created := createSyscallPacketReadWaiter(reader); created { 32 return readWaiter, true 33 } 34 return nil, false 35 }