Packet Sniffer SDK DLL Edition HNQueue :: Events :: QueSetOnPacketRecv Previous Next
Sets the address and the parameter value for the OnPacketReceive event handler
(see HNFN_PKTRECEIVE ).
Syntax: FARPROC __stdcall QueSetOnPacketRecv(HANDLE hQue, FARPROC pfOnPacketReceive, DWORD_PTR Param); Parameters: hQue [in] HNQueuer object handle. pfOnPacketReceive [in] Event handler function address.
This function must be declared as HNFN_PKTRECEIVE . Param [in] Event handler parameter. This parameter is sent to the event handler each time it is called. Return values: If the function succeeds the return value will be the value of the pfOnPacketReceive parameter.
Description: Use QueSetOnPacketRecv to set the address and the parameter value for the OnPacketReceive
event handler.
This event handler is functionally identical to
HNAdapter.OnPacketReceive event handler. The
main difference is that it is called in the HNQueue thread context,
bypassing HNAdapter.OnPacketReceive event
handler.
This enables us to increase the time of a packet processing in your application, for each packet
separately. Thus, one can have real-time numerous packets processing without packet loss if the queue
parameters for a particular task are calculated.
You should remember that OnPacketReceive event handler processing occurs
after QueGetFullItem function call, that is why when you finish
working with the queue element, it should be returned to the end of the queue by
QueReturnFreeItem function call.
//---------------------------------------------------------------------------
// Event handler OnPacketReceive of the HNQueue object
//---------------------------------------------------------------------------
void __sdtcall OnPacketReceive(DWORD_PTR Param, DWORD_PTR ThParam, HANDLE hPacket,
LPVOID pPacketData, DWORD IncPacketSize)
{
ETHERNET_HEADER *pEth;
switch(PktGetMediumType(hPacket))
{
case atEthernet:
pEth = (ETHERNET_HEADER *)pPacketData;
...
break;
default:
return;
}
...
QueReturnFreeItem(hQue,hPacket);
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
} //---------------------------------------------------------------------------
// Event handler OnPacketReceive of the HNQueue object
//---------------------------------------------------------------------------
procedure OnPacketReceive(Param: Pointer; ThParam: Pointer; hPacket,
pPacketData: Pointer; IncPacketSize: Cardinal); stdcall;
var
pEth: PETHERNET_HEADER;
begin
case (PktGetMediumType(hPacket)) of
atEthernet:
pEth := PETHERNET_HEADER(pPacketData);
...
break;
else:
Exit;
end;
...
QueReturnFreeItem(hQue,hPacket);
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
end;
See also: HNQueue ,
HNPacket ,
AdpSetOnPacketRecv ,
PktGetPacketData ,
PktGetIncPacketSize