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>
This commit is contained in:
Simon Rozman 2020-10-29 06:21:32 +01:00
parent 1170f56446
commit e11897e343
4 changed files with 11 additions and 27 deletions

View File

@ -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;
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:

View File

@ -11,7 +11,6 @@ EXPORTS
WintunGetAdapterLUID
WintunGetAdapterName
WintunGetVersion
WintunIsPacketAvailable
WintunReceivePacket
WintunReceiveRelease
WintunSendPacket

View File

@ -147,12 +147,6 @@ WintunEndSession(_In_ TUN_SESSION *Session)
HeapFree(ModuleHeap, 0, Session);
}
BOOL WINAPI
WintunIsPacketAvailable(_In_ TUN_SESSION *Session)
{
return Session->Send.Head != InterlockedGetU(&Session->Descriptor.Send.Ring->Tail);
}
WINTUN_STATUS WINAPI
WintunWaitForPacket(_In_ TUN_SESSION *Session, _In_ DWORD Milliseconds)
{

View File

@ -260,15 +260,6 @@ typedef void(WINAPI *WINTUN_END_SESSION_FUNC)(_In_ WINTUN_SESSION_HANDLE Session
*/
#define WINTUN_MAX_IP_PACKET_SIZE 0xFFFF
/**
* Peeks if there is a packet available for reading.
*
* @param Session Wintun session handle obtained with WintunStartSession
*
* @return Non-zero if there is a packet available; zero otherwise.
*/
BOOL(WINAPI *WINTUN_IS_PACKET_AVAILABLE_FUNC)(_In_ WINTUN_SESSION_HANDLE Session);
/**
* Waits for a packet to become available for reading.
*