2009年5月7日 星期四

Network Packet handling (receiving/sending) architecture

Receiving (in a single thread/process)
while (ExistFlag is not set) {
sleep(very-short-term-time); /* make the CPU not too busy, So CPU can context-switch to service other tasks */
select (rfds, long term timeout); /* the CPU will busy polling all the specified rfds, so the cpu was very busy? */
if (retval of select > 0) {
recv(specified-fd);
}
} /*while*/

Sending (in a single thread/process)
while (ExistFlag is not set) {
/* No-need to sleep to speedup the response time of sending packets */
select (wfds, long term timeout); /* the CPU will busy polling all the specified rfds, so the cpu was very busy? */
if (retval of select > 0) {
send(specified-fd);
}
} /*while*/

沒有留言: