Presentation is loading. Please wait.

Presentation is loading. Please wait.

I/O Multiplexing. TCP Echo Client: I/O operation is sequential !! tcpcliserv/tcpcli01.c: lib/str_cli.c: TCP Client TCP Server stdin stdout fgets fputs.

Similar presentations


Presentation on theme: "I/O Multiplexing. TCP Echo Client: I/O operation is sequential !! tcpcliserv/tcpcli01.c: lib/str_cli.c: TCP Client TCP Server stdin stdout fgets fputs."— Presentation transcript:

1 I/O Multiplexing

2 TCP Echo Client: I/O operation is sequential !! tcpcliserv/tcpcli01.c: lib/str_cli.c: TCP Client TCP Server stdin stdout fgets fputs writen readline

3 I/O Models

4 Blocking I/O Model

5 Nonblocking I/O Model

6 I/O Multiplexing Model

7 Signal Driven I/O Model

8 Asynchronous I/O Model  Synchronous vs. Asynchronous I/O  A synchronous I/O operation causes the requesting process to be blocked until that I/O operation completes.  An asynchronous I/O operation does not cause the requesting process to be blocked.

9 Performance select() Ready! read() Ready! read() Blocking I/O I/O Multiplexing

10 Usage of I/O Multiplexing  Client  handles an interactive input and a socket  handles multiple sockets at the same time  Server  handles both a listening socket and its connected socket  handles both TCP and UDP  handles multiple services and perhaps multiple protocols (e.g., inetd daemon)

11 Select Functions  Wait for any one of multiple events to occur and wake up the process only when  one or more of these events occurs  or, a specified amount of time has passed  wait forever: timeout = NULL  wait up to a fixed amount of time  polling: do not wait at all: timer value = 0  readset, writeset, exceptset after select returns may be changed  Need to set them again for testing file descriptors ready ready ? Read set Write set Exception set readwrite exception handling #include /* UNIX */ #include /* Windows */ int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, const struct timeval *timeout); Returns: count of read desciptors if positive, 0 on timeout, -1 on error

12 How to Manipulate Descriptor Sets  Descriptor sets(fd_set): array of integers(FD_SETSIZE)  if fdset == NULL, no interest on the condition  caution: value result arguments  Macros

13 Conditions for Descriptor Ready  A socket is ready for reading (readable)  data in socket receive buffer >= low-water mark SO_RCVLOWAT (==1, default)  read-half of connection is closed (TCP has received a FIN)  listening socket and # of completed connections > 0  socket error is pending  A socket is ready for writing (writable)  available space in socket send buffer >= low-water mark SO_SNDLOWAT ( == 2048, default (TCP, UDP))  write-half connection is closed: write() will generate SIGPIPE and return error EPIPE  A socket using nonblocking connect has completed the connection, or the connect has failed  socket error is pending  Socket has an exception condition pending if  there exists out-of-band data  still at out-of-band mark

14 Filling the Pipe: Echo C/S  In stop-and-wait mode  response time = RTT(round-trip time) + server’s processing time(=0)  batch mode 로 (file 을 stdin 으로 redirection 해서 ) 1000 line 을 보내면 1000 x response time  Continuous Tx  Fill the pipe TCP Client TCP Server stdin stdout fgets fputs writen readline

15 str_cli Function - using I/O Multiplexing EoF on input  close socket  남은 reply 를 socket 에서 read 불가능

16 str_cli Function (Revisited)

17 TCP Echo Iterative Server

18 TCP Echo Iterative Server Program


Download ppt "I/O Multiplexing. TCP Echo Client: I/O operation is sequential !! tcpcliserv/tcpcli01.c: lib/str_cli.c: TCP Client TCP Server stdin stdout fgets fputs."

Similar presentations


Ads by Google