multithreading - Thread in driver don't send packets -


i have this ndis filter driver. try start in driver thread, send packet every 10 seconds.

to that, use code:

large_integer timeprev, timenow; void threadedaction() {     while(1)     {         kequerysystemtime(&timenow);         if(nbltosend && (timenow.quadpart - timeprev.quadpart)>100000000)         {             ndisfsendnetbufferlists(nbltosend->sourcehandle, nbltosend, 0, 0);             kequerysystemtime(&timeprev);         }     } } 

the function started pscreatesystemthread in driverentry.
but not sends packet.
try use this:

void threadedaction() {     while(1)     {         if(nbltosend)         {             ndisfsendnetbufferlists(nbltosend->sourcehandle, nbltosend, 0, 0);         }     } } 

this code sends packet non stop.

the following code creates new file packet every 10 seconds(createfiles function), but don't sends packet:

large_integer timeprev, timenow; void threadedaction() {     while(1)     {         kequerysystemtime(&timenow);         if(nbltosend && (timenow.quadpart - timeprev.quadpart)>100000000)         {             pmdl pmdl = net_buffer_current_mdl(net_buffer_list_first_nb(nbltosend));             createfiles(null,(char*)mmgetmdlvirtualaddress(pmdl),mmgetmdlbytecount(pmdl));             ndisfsendnetbufferlists(nbltosend->sourcehandle, nbltosend, 0, 0);             kequerysystemtime(&timeprev);         }     } } 

why it's happened, , can send packet every 10 seconds?

the ndis6 programming model asynchronous. means when call ndisfsendnetbufferlists, give ownership of nbl. cannot reuse nbl until returned filter via filterreturnnetbufferlists callback.

so first off, need change code more this:

pnet_buffer_list nbltosend;  void filterreturnnetbufferlists(pnet_buffer_list nblchain) {     each nbl in nblchain     {         if(nbl->sourcehandle == myfilterhandle)             nbltosend = nbl;         else             ndisfreturnnetbufferlists(nbl);     } }  void threadedaction() {     while(1)     {         if(nbltosend)         {             pnet_buffer_list tempnbl = nbltosend;             nbltosend = null;             ndisfsendnetbufferlists(tempnbl);         }     } } 

this way, honor ndis rule: not send nbl again until it's been returned you.

next up, looping highly inefficient. implemented, loop consume 100% of cpu, busily counting down nanoseconds until it's time send packet. instead, use timer. system call thread when 10 seconds have elapsed.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -