github.com/yaling888/clash@v1.53.0/listener/tun/device/device.go (about) 1 package device 2 3 // Device is the interface that implemented by network layer devices (e.g. tun), 4 type Device interface { 5 // Name returns the current name of the device. 6 Name() string 7 8 // Type returns the driver type of the device. 9 Type() string 10 11 // Read one or more packets from the Device (without any additional headers). 12 // On a successful read it returns the number of packets read, and sets 13 // packet lengths within the sizes slice. len(sizes) must be >= len(buffs). 14 // A nonzero offset can be used to instruct the Device on where to begin 15 // reading into each element of the buffs slice. 16 Read(buffs [][]byte, sizes []int, offset int) (n int, err error) 17 18 // Write one or more packets to the device (without any additional headers). 19 // On a successful write it returns the number of packets written. A nonzero 20 // offset can be used to instruct the Device on where to begin writing from 21 // each packet contained within the buffs slice. 22 Write(buffs [][]byte, offset int) (int, error) 23 24 // Close stops and closes the device. 25 Close() error 26 27 // UseEndpoint work for gVisor stack 28 UseEndpoint() error 29 30 // UseIOBased work for other ip stack 31 UseIOBased() error 32 33 // BatchSize returns the preferred/max number of packets that can be read or 34 // written in a single read/write call. BatchSize must not change over the 35 // lifetime of a Device. 36 BatchSize() int 37 38 Offset() int 39 40 MTU() uint32 41 }