tun: windows: delay initial write
Otherwise we provoke Wintun 0.3.
This commit is contained in:
parent
f361e59001
commit
13abbdf14b
@ -11,6 +11,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
@ -41,6 +42,7 @@ type NativeTun struct {
|
||||
wt *wintun.Wintun
|
||||
tunFileRead *os.File
|
||||
tunFileWrite *os.File
|
||||
haveRegisteredWriteBuffer int32
|
||||
tunLock sync.Mutex
|
||||
close bool
|
||||
rdBuff *exchgBufRead
|
||||
@ -140,12 +142,7 @@ func (tun *NativeTun) openTUN() error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
firstSize := (*uint32)(unsafe.Pointer(&tun.wrBuff.data[0]))
|
||||
saved := *firstSize
|
||||
*firstSize = 0
|
||||
// Set the maximum buffer length with an invalid write.
|
||||
tun.tunFileWrite.Write(tun.wrBuff.data[:])
|
||||
*firstSize = saved
|
||||
atomic.StoreInt32(&tun.haveRegisteredWriteBuffer, 0)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -324,6 +321,15 @@ func (tun *NativeTun) Flush() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if atomic.CompareAndSwapInt32(&tun.haveRegisteredWriteBuffer, 0, 1) {
|
||||
firstSize := (*uint32)(unsafe.Pointer(&tun.wrBuff.data[0]))
|
||||
saved := *firstSize
|
||||
*firstSize = 0
|
||||
// Set the maximum buffer length with an invalid write.
|
||||
tun.tunFileWrite.Write(tun.wrBuff.data[:])
|
||||
*firstSize = saved
|
||||
}
|
||||
|
||||
for {
|
||||
_, err = file.Write(tun.wrBuff.data[:tun.wrBuff.offset])
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user