참고문헌 : etcp unp my program

10
Enhancing Your Enhancing Your Network Programming Skill Network Programming Skill - Part 2 - Part 2 Programming Tips for helping your Programming Tips for helping your ARQ design Project ARQ design Project 참참참참 : Etcp Unp My Program

Upload: almira

Post on 17-Jan-2016

85 views

Category:

Documents


3 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 참고문헌 :  Etcp Unp My Program

Enhancing YourEnhancing YourNetwork Programming SkillNetwork Programming Skill- Part 2- Part 2

Programming Tips for helping your ARQ Programming Tips for helping your ARQ design Projectdesign Project

참고문헌 : Etcp

Unp

My Program

Page 2: 참고문헌 :  Etcp Unp My Program

Making Your Apps Event DrivenMaking 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? )

Page 3: 참고문헌 :  Etcp Unp My Program

Timers in UNIX/LinuxTimers 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>int getitimer(ITIMER_REAL, struct itimerval *value);int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue); struct itimerval { struct timeval it_interval; /* next value */ struct timeval it_value; /* current value */ }; struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */

Page 4: 참고문헌 :  Etcp Unp My Program

Multiple Timeouts using select()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 errorunsigned int timeout( void (*handler)(void *), void *arg, int msec ); Returns: timer ID to be used in untimeout callvoid untimeout( unsigned int timerid );

/* 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

Examples

Page 5: 참고문헌 :  Etcp Unp My Program

Tselect() source from ‘etcp’ Tselect() source from ‘etcp’

lib/tselect.c

Page 6: 참고문헌 :  Etcp Unp My Program
Page 7: 참고문헌 :  Etcp Unp My Program
Page 8: 참고문헌 :  Etcp Unp My Program
Page 9: 참고문헌 :  Etcp Unp My Program

Internet Checksum AlgorithmInternet Checksum Algorithm

Page 10: 참고문헌 :  Etcp Unp My Program

How to simulate packet error & lostHow to simulate packet error & lost