summaryrefslogtreecommitdiffhomepage
path: root/tun
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-04-03 05:40:35 +0200
committerSimon Rozman <simon@rozman.si>2019-04-03 05:41:38 +0200
commit421c1f9143347d279c5a296a302720754b2a21b2 (patch)
tree1d7afbe441d5b5fa621ad1e9cb19650454a7b25a /tun
parentac25702eaf13bb2243f02130ae271ff600f75209 (diff)
tun: windows: Attempt to reopen handle on all errors
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tun')
-rw-r--r--tun/tun_windows.go24
1 files changed, 9 insertions, 15 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go
index 948f08d..4d26dce 100644
--- a/tun/tun_windows.go
+++ b/tun/tun_windows.go
@@ -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,12 +260,13 @@ 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) {
- tun.closeTUN()
- continue
+ if tun.close {
+ return 0, err
}
- return 0, err
+ tun.closeTUN()
+ continue
}
tun.rdBuff.offset = 0
tun.rdBuff.avail = uint32(n)
@@ -298,11 +292,11 @@ func (tun *NativeTun) Flush() error {
tun.wrBuff.packetNum = 0
tun.wrBuff.offset = 0
if err != nil {
- if tun.shouldReopenHandle(err) {
- tun.closeTUN()
- continue
+ if tun.close {
+ return err
}
- return err
+ tun.closeTUN()
+ continue
}
return nil
}