07.03.2013 Views

Multithreading Multi-Threaded Programming

Multithreading Multi-Threaded Programming

Multithreading Multi-Threaded Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Timer in worker thread<br />

//the while loop will continue sending packets every MT_INTERVAL until the FrameCapture thread<br />

signals the g_event_FrameCaptured which means the corresponding response frame has arrived.<br />

UINT SendThreadProc( LPVOID pParam )<br />

{<br />

pcap_sendpacket( … …); //send a frame out<br />

while(::WaitForSingleObject(g_event_FrameCaptured, MT_INTERVAL) != WAIT_OBJECT_0) {<br />

pcap_sendpacket( … …); //no response until timeout, so send the frame again, or skip to send the next.<br />

………………<br />

}<br />

return 0;<br />

}<br />

//signal the event when a frame is captured<br />

UINT ReceiveThreadProc( LPVOID pParam )<br />

{<br />

while(::WaitForSingleObject(g_event_Done,0) != WAIT_OBJECT_0){<br />

res = pcap_next_ex(……);<br />

if(res == 0){ continue;}<br />

else{<br />

……<br />

g_event_FrameCaptured.SetEvent();<br />

…….<br />

}<br />

return 0;<br />

}<br />

35<br />

Advanced Windows Network <strong>Programming</strong><br />

11/11/12

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!