api expose Send.TailMoved event to clients
This allows clients to use it in WaitForMultipleObjects(). Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
c8004933c1
commit
efbc70635b
@ -17,4 +17,3 @@ EXPORTS
|
|||||||
WintunSetAdapterName
|
WintunSetAdapterName
|
||||||
WintunSetLogger
|
WintunSetLogger
|
||||||
WintunStartSession
|
WintunStartSession
|
||||||
WintunWaitForPacket
|
|
||||||
|
@ -65,7 +65,11 @@ typedef struct _TUN_SESSION
|
|||||||
} TUN_SESSION;
|
} TUN_SESSION;
|
||||||
|
|
||||||
WINTUN_STATUS WINAPI
|
WINTUN_STATUS WINAPI
|
||||||
WintunStartSession(_In_ const WINTUN_ADAPTER *Adapter, _In_ DWORD Capacity, _Out_ TUN_SESSION **Session)
|
WintunStartSession(
|
||||||
|
_In_ const WINTUN_ADAPTER *Adapter,
|
||||||
|
_In_ DWORD Capacity,
|
||||||
|
_Out_ TUN_SESSION **Session,
|
||||||
|
_Out_ HANDLE *ReadWait)
|
||||||
{
|
{
|
||||||
TUN_SESSION *s = HeapAlloc(ModuleHeap, HEAP_ZERO_MEMORY, sizeof(TUN_SESSION));
|
TUN_SESSION *s = HeapAlloc(ModuleHeap, HEAP_ZERO_MEMORY, sizeof(TUN_SESSION));
|
||||||
if (!s)
|
if (!s)
|
||||||
@ -127,6 +131,7 @@ WintunStartSession(_In_ const WINTUN_ADAPTER *Adapter, _In_ DWORD Capacity, _Out
|
|||||||
(void)InitializeCriticalSectionAndSpinCount(&s->Receive.Lock, LOCK_SPIN_COUNT);
|
(void)InitializeCriticalSectionAndSpinCount(&s->Receive.Lock, LOCK_SPIN_COUNT);
|
||||||
(void)InitializeCriticalSectionAndSpinCount(&s->Send.Lock, LOCK_SPIN_COUNT);
|
(void)InitializeCriticalSectionAndSpinCount(&s->Send.Lock, LOCK_SPIN_COUNT);
|
||||||
*Session = s;
|
*Session = s;
|
||||||
|
*ReadWait = s->Descriptor.Send.TailMoved;
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
cleanupHandle:
|
cleanupHandle:
|
||||||
CloseHandle(s->Handle);
|
CloseHandle(s->Handle);
|
||||||
@ -156,12 +161,6 @@ WintunEndSession(_In_ TUN_SESSION *Session)
|
|||||||
HeapFree(ModuleHeap, 0, Session);
|
HeapFree(ModuleHeap, 0, Session);
|
||||||
}
|
}
|
||||||
|
|
||||||
WINTUN_STATUS WINAPI
|
|
||||||
WintunWaitForPacket(_In_ TUN_SESSION *Session, _In_ DWORD Milliseconds)
|
|
||||||
{
|
|
||||||
return WaitForSingleObject(Session->Descriptor.Send.TailMoved, Milliseconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
WINTUN_STATUS WINAPI
|
WINTUN_STATUS WINAPI
|
||||||
WintunReceivePacket(_In_ TUN_SESSION *Session, _Out_bytecapcount_(*PacketSize) BYTE **Packet, _Out_ DWORD *PacketSize)
|
WintunReceivePacket(_In_ TUN_SESSION *Session, _Out_bytecapcount_(*PacketSize) BYTE **Packet, _Out_ DWORD *PacketSize)
|
||||||
{
|
{
|
||||||
|
34
api/wintun.h
34
api/wintun.h
@ -250,12 +250,18 @@ typedef void *WINTUN_SESSION_HANDLE;
|
|||||||
*
|
*
|
||||||
* @param Session Pointer to a variable to receive Wintun session handle
|
* @param Session Pointer to a variable to receive Wintun session handle
|
||||||
*
|
*
|
||||||
|
* @param ReadWait Pointer to receive event handle to wait for available data when reading. Should
|
||||||
|
* WintunReceivePackets return ERROR_NO_MORE_ITEMS (after spinning on it for a while under heavy
|
||||||
|
* load), wait for this event to become signaled before retrying WintunReceivePackets. Do not call
|
||||||
|
* CloseHandle on this event - it is managed by the session.
|
||||||
|
*
|
||||||
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
|
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
|
||||||
*/
|
*/
|
||||||
typedef WINTUN_STATUS(WINAPI *WINTUN_START_SESSION_FUNC)(
|
typedef WINTUN_STATUS(WINAPI *WINTUN_START_SESSION_FUNC)(
|
||||||
_In_ WINTUN_ADAPTER_HANDLE Adapter,
|
_In_ WINTUN_ADAPTER_HANDLE Adapter,
|
||||||
_In_ DWORD Capacity,
|
_In_ DWORD Capacity,
|
||||||
_Out_ WINTUN_SESSION_HANDLE *Session);
|
_Out_ WINTUN_SESSION_HANDLE *Session,
|
||||||
|
_Out_ HANDLE *ReadWait);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends Wintun session.
|
* Ends Wintun session.
|
||||||
@ -269,20 +275,6 @@ typedef void(WINAPI *WINTUN_END_SESSION_FUNC)(_In_ WINTUN_SESSION_HANDLE Session
|
|||||||
*/
|
*/
|
||||||
#define WINTUN_MAX_IP_PACKET_SIZE 0xFFFF
|
#define WINTUN_MAX_IP_PACKET_SIZE 0xFFFF
|
||||||
|
|
||||||
/**
|
|
||||||
* Waits for a packet to become available for reading.
|
|
||||||
*
|
|
||||||
* @param Session Wintun session handle obtained with WintunStartSession
|
|
||||||
*
|
|
||||||
* @param Milliseconds The time-out interval, in milliseconds. If a nonzero value is specified, the function waits
|
|
||||||
* until a packet is available or the interval elapses. If Milliseconds is zero, the function
|
|
||||||
* does not enter a wait state if a packet is not available; it always returns immediately.
|
|
||||||
* If Milliseconds is INFINITE, the function will return only when a packet is available.
|
|
||||||
*
|
|
||||||
* @return See WaitForSingleObject() for return values.
|
|
||||||
*/
|
|
||||||
typedef WINTUN_STATUS(WINAPI *WINTUN_WAIT_FOR_PACKET_FUNC)(_In_ WINTUN_SESSION_HANDLE Session, _In_ DWORD Milliseconds);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves one or packet. After the packet content is consumed, call WintunReceiveRelease with Packet returned
|
* Retrieves one or packet. After the packet content is consumed, call WintunReceiveRelease with Packet returned
|
||||||
* from this function to release internal buffer. This function is thread-safe.
|
* from this function to release internal buffer. This function is thread-safe.
|
||||||
@ -301,8 +293,10 @@ typedef WINTUN_STATUS(WINAPI *WINTUN_WAIT_FOR_PACKET_FUNC)(_In_ WINTUN_SESSION_H
|
|||||||
* ERROR_SUCCESS on success.
|
* ERROR_SUCCESS on success.
|
||||||
* Regardless, if the error was returned, some packets might have been read nevertheless.
|
* Regardless, if the error was returned, some packets might have been read nevertheless.
|
||||||
*/
|
*/
|
||||||
typedef WINTUN_STATUS(WINAPI *WINTUN_RECEIVE_PACKETS_FUNC)
|
typedef WINTUN_STATUS(WINAPI *WINTUN_RECEIVE_PACKETS_FUNC)(
|
||||||
(_In_ WINTUN_SESSION_HANDLE *Session, _Out_bytecapcount_(*PacketSize) BYTE **Packet, _Out_ DWORD *PacketSize);
|
_In_ WINTUN_SESSION_HANDLE *Session,
|
||||||
|
_Out_bytecapcount_(*PacketSize) BYTE **Packet,
|
||||||
|
_Out_ DWORD *PacketSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Releases internal buffer after the received packet has been processed by the client. This function is thread-safe.
|
* Releases internal buffer after the received packet has been processed by the client. This function is thread-safe.
|
||||||
@ -329,8 +323,10 @@ typedef void(WINAPI *WINTUN_RECEIVE_RELEASE_FUNC)(_In_ WINTUN_SESSION_HANDLE *Se
|
|||||||
* ERROR_BUFFER_OVERFLOW Wintun buffer is full;
|
* ERROR_BUFFER_OVERFLOW Wintun buffer is full;
|
||||||
* ERROR_SUCCESS on success.
|
* ERROR_SUCCESS on success.
|
||||||
*/
|
*/
|
||||||
typedef WINTUN_STATUS(WINAPI *WINTUN_ALLOCATE_SEND_PACKET_FUNC)
|
typedef WINTUN_STATUS(WINAPI *WINTUN_ALLOCATE_SEND_PACKET_FUNC)(
|
||||||
(_In_ WINTUN_SESSION_HANDLE *Session, _In_ DWORD PacketSize, _Out_bytecapcount_(PacketSize) BYTE **Packet);
|
_In_ WINTUN_SESSION_HANDLE *Session,
|
||||||
|
_In_ DWORD PacketSize,
|
||||||
|
_Out_bytecapcount_(PacketSize) BYTE **Packet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the packet and releases internal buffer. WintunSendPacket is thread-safe, but the WintunAllocateSendPacket
|
* Sends the packet and releases internal buffer. WintunSendPacket is thread-safe, but the WintunAllocateSendPacket
|
||||||
|
Loading…
Reference in New Issue
Block a user