aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2020-10-29 06:21:32 +0100
committerSimon Rozman <simon@rozman.si>2020-10-31 10:41:46 +0100
commite11897e34329c59d993b471ceddfbd146ccbef1b (patch)
tree2917b3bad6809a704214a47a88374c683613902c /README.md
parentapi: move files from root to wintun folder within Zip (diff)
downloadwintun-e11897e34329c59d993b471ceddfbd146ccbef1b.tar.xz
wintun-e11897e34329c59d993b471ceddfbd146ccbef1b.zip
api: depretiate WintunIsPacketAvailable()
Spinning on the WintunReceivePacket() while it returns ERROR_NO_MORE_ITEMS achieves the same. Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'README.md')
-rw-r--r--README.md22
1 files changed, 11 insertions, 11 deletions
diff --git a/README.md b/README.md
index eabaf95..8afe261 100644
--- a/README.md
+++ b/README.md
@@ -58,7 +58,6 @@ Once adapter is created, use the following functions to start a session and tran
- `WintunStartSession()` starts a session. One adapter may have only one session.
- `WintunEndSession()` ends and frees the session.
- `WintunIsPacketAvailable()` checks if there is a receive packet available.
-- `WintunWaitForPacket()` waits for a receive packet to become available.
- `WintunReceivePacket()` receives one packet.
- `WintunReceiveRelease()` releases internal buffer after client processed the receive packet.
- `WintunAllocateSendPacket()` allocates memory for send packet.
@@ -69,23 +68,24 @@ Once adapter is created, use the following functions to start a session and tran
Reading packets from the adapter may be done as:
```C
-// TODO: Preallocate WINTUN_PACKET *Queue linked list with WINTUN_MAX_IP_PACKET_SIZE packets.
for (;;) {
- if (!WintunIsPacketAvailable(Session))
- WintunWaitForPacket(Session, INFINITE);
- for (WINTUN_PACKET *p = Queue; p && p->Size <= WINTUN_MAX_IP_PACKET_SIZE; p = p->Next)
- p->Size = DWORD_MAX;
BYTE *Packet;
DWORD PacketSize;
DWORD Result = WintunReceivePacket(Session, &Packet, &PacketSize);
- if (Result != ERROR_SUCCESS)
- return Result;
- // TODO: Process packet.
- WintunReceiveRelease(Session, Packet);
+ switch (Result) {
+ case ERROR_SUCCESS:
+ // TODO: Process packet.
+ WintunReceiveRelease(Session, Packet);
+ break;
+ case ERROR_NO_MORE_ITEMS:
+ WintunWaitForPacket(Session, INFINITE);
+ continue;
+ }
+ return Result;
}
```
-It may be desirable to spin on `WintunIsPacketAvailable()` for some time under heavy use before waiting with `WintunWaitForPacket()`, in order to reduce latency.
+It may be desirable to spin on `WintunReceivePacket()` while it returns `ERROR_NO_MORE_ITEMS` for some time under heavy use before waiting with `WintunWaitForPacket()`, in order to reduce latency.
Writing packets to the adapter may be done as: