aboutsummaryrefslogtreecommitdiffstats
path: root/api/session.c
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2020-11-18 17:35:42 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-27 14:52:03 +0100
commitecf70261da7b42db080df5047685850ab39b58fe (patch)
treec541455593bceabf96906fa74b3df8803a49686f /api/session.c
parentapi: allow header to be mit (diff)
downloadwintun-ecf70261da7b42db080df5047685850ab39b58fe.tar.xz
wintun-ecf70261da7b42db080df5047685850ab39b58fe.zip
api: skip notifying driver when there are no receive packets yet
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'api/session.c')
-rw-r--r--api/session.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/api/session.c b/api/session.c
index c48d5cb..a900a0a 100644
--- a/api/session.c
+++ b/api/session.c
@@ -293,8 +293,10 @@ WintunSendPacket(_In_ TUN_SESSION *Session, _In_ const BYTE *Packet)
TUN_RING_WRAP(Session->Receive.TailRelease + AlignedPacketSize, Session->Capacity);
Session->Receive.PacketsToRelease--;
}
- WriteULongRelease(&Session->Descriptor.Receive.Ring->Tail, Session->Receive.TailRelease);
- if (ReadAcquire(&Session->Descriptor.Receive.Ring->Alertable))
- SetEvent(Session->Descriptor.Receive.TailMoved);
+ if (Session->Descriptor.Receive.Ring->Tail != Session->Receive.TailRelease) {
+ WriteULongRelease(&Session->Descriptor.Receive.Ring->Tail, Session->Receive.TailRelease);
+ if (ReadAcquire(&Session->Descriptor.Receive.Ring->Alertable))
+ SetEvent(Session->Descriptor.Receive.TailMoved);
+ }
LeaveCriticalSection(&Session->Receive.Lock);
}