diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-21 14:43:04 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-21 14:45:41 -0600 |
commit | 6440f010eec82abb9c999771a8f493af44c6b937 (patch) | |
tree | 187207b768cb2bb477879a1abfad8b732bbece45 /tun/tun_windows.go | |
parent | tun: windows: add dummy overlapped events back (diff) | |
download | wireguard-go-6440f010eec82abb9c999771a8f493af44c6b937.tar.xz wireguard-go-6440f010eec82abb9c999771a8f493af44c6b937.zip |
receive: implement flush semantics
Diffstat (limited to '')
-rw-r--r-- | tun/tun_windows.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go index dcb414a..fffd802 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -281,7 +281,11 @@ func (tun *NativeTun) Read(buff []byte, offset int) (int, error) { // Note: flush() and putTunPacket() assume the caller comes only from a single thread; there's no locking. -func (tun *NativeTun) flush() error { +func (tun *NativeTun) Flush() error { + if tun.wrBuff.offset == 0 { + return nil + } + // Get TUN data pipe. file, err := tun.getTUN() if err != nil { @@ -322,7 +326,7 @@ func (tun *NativeTun) putTunPacket(buff []byte) error { if tun.wrBuff.packetNum >= packetExchangeMax || tun.wrBuff.offset+pSize >= packetExchangeSize { // Exchange buffer is full -> flush first. - err := tun.flush() + err := tun.Flush() if err != nil { return err } @@ -345,9 +349,7 @@ func (tun *NativeTun) Write(buff []byte, offset int) (int, error) { if err != nil { return 0, err } - - // Flush write buffer. - return len(buff) - offset, tun.flush() + return len(buff) - offset, nil } // |