100 likes | 358 Views
Enhancing Your Network Programming Skill - Part 2 Programming Tips for helping your ARQ design Project. 참고문헌 : Etcp Unp My Program. Making Your Apps Event Driven. Types of events in protocols and networked application Packet arrival User input Timeout API call
E N D
Enhancing YourNetwork Programming Skill- Part 2Programming Tips for helping your ARQ design Project 참고문헌: Etcp Unp My Program
Making Your Apps Event Driven • Types of events in protocols and networked application • Packet arrival • User input • Timeout • API call • 만일, API도 UNIX domain socket(일종의 socket descriptor임)이라면 select()로 API call이 발생했음을 확인 가능 • 다만, select()는 timeout은 하나만 가능 • How to support multiple timeouts using select() ? • You can make it ! select()로 확인 가능 (Ready or timeout? )
Timers in UNIX/Linux • Using SIGALRM signal: 초 단위 • Interval timer: 실제는 10 msec 단위로 작동 • select(): 실제 10 msec 단위로 작동 signal(SIGALRM, handler); // or sigaction(…) … alarm(seconds); // set timeout timer … void handler(in signo) { …. }; // actions in timeout event #include <sys/time.h> intgetitimer(ITIMER_REAL, structitimerval *value); intsetitimer(int which, const structitimerval *value, structitimerval *ovalue); structitimerval { structtimevalit_interval; /* next value */ structtimevalit_value; /* current value */ }; structtimeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */
Multiple Timeouts using select() #include “etcp.h” int tselect( int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset ); Returns: # of ready events, 0 if no remaining events, -1 on error unsigned int timeout( void (*handler)(void *), void *arg, int msec ); Returns: timer ID to be used in untimeout call void untimeout( unsigned int timerid ); Examples /* call retransmit(packet) after 1500 msec (timeout) */ rxtimer = timeout(retransmit, (void *) packet, 1500 ); UItimer = timeout(useridle, NULL, 30000); … n = tselectmaxfdp1, &readset, &writeset, &exceptset ); … // if received ACK, untimeout(rxtimer); // reset the timer
Tselect() source from ‘etcp’ lib/tselect.c