Update
This commit is contained in:
1 parent
3530afb854
commit
6903fcff27
2146 files changed
+112256
-190703
No files matched your search
+11
-6
@@ -59,7 +59,7 @@ func nanotime() int64
|
||||
|
||||
// CreateTUN creates a Wintun interface with the given name. Should a Wintun
|
||||
// interface with the same name exist, it is reused.
|
||||
func CreateTUN(ifname string, mtu int) (Device, error) {
|
||||
func CreateTUN(ifname string, mtu int, _ ...Option) (Device, error) {
|
||||
return CreateTUNWithRequestedGUID(ifname, WintunStaticRequestedGUID, mtu)
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func (tun *NativeTun) BatchSize() int {
|
||||
|
||||
// Note: Read() and Write() assume the caller comes only from a single thread; there's no locking.
|
||||
|
||||
func (tun *NativeTun) Read(bufs [][]byte, sizes []int, offset int) (int, error) {
|
||||
func (tun *NativeTun) Read(slab []byte, packets []ReadPacket) (int, error) {
|
||||
tun.running.Add(1)
|
||||
defer tun.running.Done()
|
||||
retry:
|
||||
@@ -160,11 +160,16 @@ retry:
|
||||
packet, err := tun.session.ReceivePacket()
|
||||
switch err {
|
||||
case nil:
|
||||
packetSize := len(packet)
|
||||
copy(bufs[0][offset:], packet)
|
||||
sizes[0] = packetSize
|
||||
dst := slab[ReadPacketSpacing : len(slab)-ReadPacketSpacing]
|
||||
if len(packet) > len(dst) {
|
||||
tun.session.ReleaseReceivePacket(packet)
|
||||
return 0, ErrTooManySegments
|
||||
}
|
||||
n := copy(dst, packet)
|
||||
packets[0].Offset = ReadPacketSpacing
|
||||
packets[0].Size = n
|
||||
tun.session.ReleaseReceivePacket(packet)
|
||||
tun.rate.update(uint64(packetSize))
|
||||
tun.rate.update(uint64(n))
|
||||
return 1, nil
|
||||
case windows.ERROR_NO_MORE_ITEMS:
|
||||
if !shouldSpin || uint64(nanotime()-start) >= spinloopDuration {
|
||||
|
||||
Reference in new issue
Block a user