Packet Sniffer SDK DLL Edition

HNQueue :: Events :: QueSetOnPacketsRecv

 Previous Next

Sets the address and the parameter value for the OnPacketsReceive event handler (see HNFN_PKTSRECEIVE).

Syntax:

FARPROC __stdcall QueSetOnPacketsRecv(HANDLE hQue, FARPROC pfOnPacketsReceive, DWORD_PTR Param);

Parameters:

hQue

[in] HNQueuer object handle.

pfOnPacketsReceive

[in] Event handler function address. This function must be declared as HNFN_PKTSRECEIVE.

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 pfOnPacketsReceive parameter.

Description:

Use QueSetOnPacketsRecv to set the address and the parameter value for the OnPacketsReceive 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.

To use OnPacketsReceive event handler, you should set ReceiveManyAtOnce flag to TRUE before QueStart function call.
You should remember that OnPacketsReceive event handler processing occurs after QueGetFullItems function call, that is why when you finish working with the queue elements, they should be returned to the end of the queue by QueReturnFreeItem(QueReturnFreeItems) function call.
//---------------------------------------------------------------------------
// Event handler OnPacketsReceive of the HNQueue object
//---------------------------------------------------------------------------
void __sdtcall OnPacketsReceive(DWORD_PTR Param, DWORD_PTR ThParam, PHANDLE hPackets, DWORD dwCount)
 {                
   for (...)
   {
      ETHERNET_HEADER *pEth;
      switch(PktGetMediumType(hPackets[...]))
      {
      case atEthernet:
        pEth = (ETHERNET_HEADER *)PktGetPacketData(hPackets[...]);
        ... 
        break;  

      default:
        return;
      }
   }   
   ...

   QueReturnFreeItems(hQue,hPackets,dwCount);
   //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 }
//---------------------------------------------------------------------------
// Event handler OnPacketsReceive of the HNQueue object
//---------------------------------------------------------------------------
procedure OnPacketsReceive(Param: Pointer; ThParam: Pointer; hPackets: Pointer; dwCount: Cardinal); stdcall;
 var
  pEth: PETHERNET_HEADER;
begin                                                                                  
   for ... do
   begin
     case (PktGetMediumType(hPackets^.[...])) of
        atEthernet:
        pEth := PETHERNET_HEADER(PktGetPacketData(hPackets^.[...]));
        ... 
        break;  

     else:
        Exit;
     end;
     ...
   end;  

   QueReturnFreeItems(hQue,hPackets,dwCount);
   //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
end;
See also:HNQueue, QueSetReceiveManyAtOnce, HNPacket, PktGetPacketData, PktGetIncPacketSize