From: Simon Rozman Date: Fri, 22 Mar 2019 11:44:14 +0000 (+0100) Subject: tun: windows: Make writing persistent too X-Git-Tag: 0.0.20190409~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a80db5e65e4c202bae184a32120017782549fdac;p=thirdparty%2Fwireguard-go.git tun: windows: Make writing persistent too Signed-off-by: Simon Rozman --- diff --git a/tun/tun_windows.go b/tun/tun_windows.go index ce6ec8c..9888e86 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -284,24 +284,26 @@ func (tun *NativeTun) Flush() error { return nil } - // Get TUN data pipe. - _, file, err := tun.getTUN() - if err != nil { - return err - } + for { + // Get TUN data pipe. + _, file, err := tun.getTUN() + if err != nil { + return err + } - // Flush write buffer. - _, err = file.Write(tun.wrBuff.data[:tun.wrBuff.offset]) - tun.wrBuff.packetNum = 0 - tun.wrBuff.offset = 0 - if err != nil { - if tun.shouldReopenHandle(err) { - tun.closeTUN() - return nil + // Flush write buffer. + _, err = file.Write(tun.wrBuff.data[:tun.wrBuff.offset]) + tun.wrBuff.packetNum = 0 + tun.wrBuff.offset = 0 + if err != nil { + if tun.shouldReopenHandle(err) { + tun.closeTUN() + continue + } + return err } - return err + return nil } - return nil } func (tun *NativeTun) putTunPacket(buff []byte) error {