tun: windows: Attempt to reopen handle on all errors
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
ac25702eaf
commit
421c1f9143
|
@ -188,13 +188,6 @@ func (tun *NativeTun) getTUN() (read *os.File, write *os.File, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tun *NativeTun) shouldReopenHandle(err error) bool {
|
||||
if pe, ok := err.(*os.PathError); ok && pe.Err == windows.ERROR_OPERATION_ABORTED {
|
||||
return !tun.close
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (tun *NativeTun) Name() (string, error) {
|
||||
return tun.wt.GetInterfaceName()
|
||||
}
|
||||
|
@ -267,13 +260,14 @@ func (tun *NativeTun) Read(buff []byte, offset int) (int, error) {
|
|||
// Fill queue.
|
||||
n, err := file.Read(tun.rdBuff.data[:])
|
||||
if err != nil {
|
||||
tun.rdBuff.offset = 0
|
||||
tun.rdBuff.avail = 0
|
||||
if tun.shouldReopenHandle(err) {
|
||||
if tun.close {
|
||||
return 0, err
|
||||
}
|
||||
tun.closeTUN()
|
||||
continue
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
tun.rdBuff.offset = 0
|
||||
tun.rdBuff.avail = uint32(n)
|
||||
}
|
||||
|
@ -298,12 +292,12 @@ func (tun *NativeTun) Flush() error {
|
|||
tun.wrBuff.packetNum = 0
|
||||
tun.wrBuff.offset = 0
|
||||
if err != nil {
|
||||
if tun.shouldReopenHandle(err) {
|
||||
if tun.close {
|
||||
return err
|
||||
}
|
||||
tun.closeTUN()
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue