diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-21 00:16:07 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-21 02:29:09 -0600 |
commit | 49ea0c9b1aca8662c2e520d84f7eed3019f2697a (patch) | |
tree | b1d55555bfc17aa971861f724f661a2e49fccf6d /tun | |
parent | ca59b60aa7767cd2ddd980d053e17ef29c52c0a3 (diff) |
tun: windows: add dummy overlapped events back
These seem basically wrong to me, but we get crashes without them.
Diffstat (limited to 'tun')
-rw-r--r-- | tun/tun_windows.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go index eca6738..dcb414a 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -46,6 +46,8 @@ type NativeTun struct { close bool rdBuff *exchgBufRead wrBuff *exchgBufWrite + rdEvent windows.Handle + wrEvent windows.Handle events chan TUNEvent errors chan error forcedMtu int @@ -96,12 +98,26 @@ func CreateTUN(ifname string) (TUNDevice, error) { return nil, err } + rde, err := windows.CreateEvent(nil, 1 /*TRUE*/, 0 /*FALSE*/, nil) + if err != nil { + wt.DeleteInterface(0) + return nil, err + } + wre, err := windows.CreateEvent(nil, 1 /*TRUE*/, 0 /*FALSE*/, nil) + if err != nil { + windows.CloseHandle(rde) + wt.DeleteInterface(0) + return nil, err + } + return &NativeTun{ wt: wt, tunName: tunNameUTF16, tunFile: windows.InvalidHandle, rdBuff: &exchgBufRead{}, wrBuff: &exchgBufWrite{}, + rdEvent: rde, + wrEvent: wre, events: make(chan TUNEvent, 10), errors: make(chan error, 1), forcedMtu: 1500, @@ -194,6 +210,9 @@ func (tun *NativeTun) Close() error { err1 = err2 } + windows.CloseHandle(tun.rdEvent) + windows.CloseHandle(tun.wrEvent) + return err1 } @@ -240,7 +259,7 @@ func (tun *NativeTun) Read(buff []byte, offset int) (int, error) { // Fill queue. var n uint32 - overlapped := &windows.Overlapped{} + overlapped := &windows.Overlapped{HEvent: tun.rdEvent} err = windows.ReadFile(file, tun.rdBuff.data[:], &n, overlapped) if err != nil { if en, ok := err.(syscall.Errno); ok && en == windows.ERROR_IO_PENDING { @@ -271,7 +290,7 @@ func (tun *NativeTun) flush() error { // Flush write buffer. var n uint32 - overlapped := &windows.Overlapped{} + overlapped := &windows.Overlapped{HEvent: tun.wrEvent} err = windows.WriteFile(file, tun.wrBuff.data[:tun.wrBuff.offset], &n, overlapped) tun.wrBuff.packetNum = 0 tun.wrBuff.offset = 0 |