I/O Multiplexing. What is I/O multiplexing? When an application needs to handle multiple I/O descriptors at the same time –E.g. file and socket descriptors,

Slides:



Advertisements
Similar presentations
Nonblocking I/O Blocking vs. non-blocking I/O
Advertisements

Socket Options. abstraction Introduction getsockopt and setsockopt function socket state Generic socket option IPv4 socket option ICMPv6 socket option.
Sop, Fan Reference: Daniel Spangenberger Computer Networks PPT-4 Socket Programming.
I/O Models Satish Krishnan. I/O Models Blocking I/O Non-blocking I/O I/O Multiplexing Signal driven I/O Asynchronous I/O.
Chapter 6 I/O Multiplexing: select and poll function.
I/O Multiplexing Road Map: 1. Motivation 2. Description of I/O multiplexing 3. Scenarios to use I/O multiplexing 4. I/O Models  Blocking I/O  Non-blocking.
Daemon Processes Long lived utility processes Often started at system boot and ended when system shuts down Run in the background with no controlling terminal.
Today’s topic Issues about sending structures with TCP. Server design alternatives: concurrent server and multiplexed server. I/O multiplexing.
Sockets CS 3516 – Computer Networks. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Distributed Computing Systems Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Computer Networks Sockets. Sockets and the OS F An end-point for Internet connection –What the application “plugs into” –OS provides Application Programming.
Computer Networks Sockets.
TDC561 Network Programming Camelia Zlatea, PhD Week 3: Unix Asynchronous Events; Signals and Alarms API.
Multimedia Networking Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Advanced Sockets Amit Mondal TA, Intro to Networking Jan 22, 2009 Recital 3 Introduction to Networking Instructor: Prof. Aleksandar Kuzmanovic.
Network Programming UNIX Internet Socket API. Everything in Unix is a File –When Unix programs do any sort of I/O, they do it by reading or writing to.
Sockets IMGD Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
I/O Multiplexing© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science.
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
1 Data Communications and Networking Socket Programming Part II: Design of Server Software Reference: Internetworking with TCP/IP, Volume III Client-Server.
I/O Multiplexing Capability of tell the kernel that wants to be notified when one or more I/O conditions are ready. For example, I/O data is available.
Socket Options Jari Kellokoski. Introduction So far we have discovered some basic usage of socket With socket options we control sockets more suitable.
1 Nonblocking I/O Nonblocking reads and writes Buffers enabling overlapped nonblocking I/O Nonblocking connect.
1 I/O Multiplexing Computer Network Programming. 2 Input from multiple sources Process keyboard sockets file A process may have multiple sources of input.
Computer Networks Sockets. Outline F Socket basics F Socket details.
Computer Network Architecture and Programming
Operating Systems Sockets. Outline F Socket basics F TCP sockets F Socket details F Socket options F Final notes F Project 3.
Lecture 8 UDP Sockets & I/O Multiplexing
Select The select function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O. int select( int nfds, fd_set*
Socket option Getsockopt ou setsockopt fcntl ioctl.
IP Multiplexing Ying Zhang EECS 489 W07.
CS4516: Medical Examiner Client/Server Evan Frenn 1.
ECE 4110 – Internetwork Programming Client-Server Model.
Signal-Driven I/O Concepts and steps for using signal-driven I/O
More on Socket API. How to Place Timeouts on Sockets (1)  Using SIGALRM signal Connection timeout 기간의 축소 Response timeout advio/dgclitimeo3.clib/connect_timeo.c.
Nonblocking I/O Blocking vs. non-blocking I/O Nonblocking input, output, accept, and connect Readings –UNP Ch16 1.
Review: How to create a TCP end point? What is the right format for sin_port and sin_addr in the sockaddr_in data structure? How many different ways we.
TELE 402 Lecture 4: I/O multi … 1 Overview Last Lecture –TCP socket and Client-Server example –Source: Chapters 4&5 of Stevens’ book This Lecture –I/O.
1 COMP/ELEC 429/556 Introduction to Computer Networks Creating a Network Application Some slides used with permissions from Edward W. Knightly, T. S. Eugene.
1 I/O Multiplexing We often need to be able to monitor multiple descriptors:We often need to be able to monitor multiple descriptors: –a generic TCP client.
CSCE 515: Computer Network Programming Select Wenyuan Xu Department of Computer Science and Engineering.
Netprog: Advanced Sockets Programming1 Advanced Sockets Programming Ref: Chapter 7,11,21,22.
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.
1 Socket Options Ref: Chapter 7. 2 Socket Options Various attributes that are used to determine the behavior of sockets.Various attributes that are used.
Socket options: a summary –Tcp options, ip options and general socket options can be examined and sometimes modified. getsockopt, setsockopt routines Some.
TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 1 Overview Last Lecture –Advanced UDP sockets and threads –Source: Chapters 22&26 of Stevens’ book.
PA3: Improving Performance with I/O Multiplexing Part 1-1: Nov. 7, Part 1-2: Nov. 10 Part 2-1: Nov. 17, Part 2-2: Nov.20.
Single Process, Concurrent, Connection-Oriented Servers (TCP) (Chapter 12)
1 Socket Options getsockopt and setsockopt functions Check options and obtain default values Generic socket options IPv4 socket options IPv6 socket options.
UNIX Internet Socket API
CMPT 471 Networking II Network Programming © Janice Regan,
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
CSCI 330 UNIX and Network Programming Unit XVII: Socket Programming Detail.
I/O Multiplexing Chap 6. I/O Models  Blocking I/O Model  Nonblocking I/O Model  I/O Multiplexing Model  Signal Driven I/O Model  Asynchronous I/O.
Ioctl Operations. ioctl Function Interface Configuration  Netstat, ifconfig command 에서 사용.
@Yuan Xue CS 283Computer Networks Spring 2013 Instructor: Yuan Xue.
More Project 1 and HW 1 stuff! Athula Balachandran Wolfgang Richter
IPv4 socket option Level => IPPROTO_IP
I/O Multiplexing.
Socket Option.
Review: TCP Client-Server Interaction
Advanced Sockets Introduction to Networking
Lecture 4 Socket Programming Issues
Chapter 07. Socket Options.
Lecture 11 Overview.
Socket Programming.
Advanced Sockets Programming
I/O Multiplexing We often need to be able to monitor multiple descriptors: a generic TCP client (like telnet) need to be able to handle unexpected situations,
Socket options: a summary
Advanced UNIX programming
Presentation transcript:

I/O Multiplexing

What is I/O multiplexing? When an application needs to handle multiple I/O descriptors at the same time –E.g. file and socket descriptors, multiple socket descriptors When I/O on any one descriptor can result in blocking

Non-forking concurrent server Concurrent Server select() C1C2C3C4C5 listenfd fd1fd2fd3fd4 fd5 Sockets  Clients 

I/O Models 1.Blocking I/O 2.Non-blocking I/O 3.I/O multiplexing – select() 4.Signal driven I/O 5.Asynchronous I/O

Blocking I/O recvfrom() No datagram ready datagram ready Copy datagram Copy completeProcess datagram System call ApplicationOperating system Wait for data Copy data to user Return ok Process blocks

Non-Blocking I/O recvfrom() No datagram ready datagram ready Copy datagram Copy completeProcess datagram System call ApplicationOperating system Copy data to user Return ok Process blocks EWOULDBLOCK recvfrom() No datagram ready System call EWOULDBLOCK recvfrom() System call

I/O Multiplexing select() No datagram ready datagram ready Copy datagram Copy completeProcess datagram System call ApplicationOperating system Wait for data Copy data to user Return ok Process blocks Return readable Process blocks recvfrom() System call

Signal driven I/O Establish SIGIO Signal handler No datagram ready datagram ready Copy datagram Copy complete Process datagram System call ApplicationOperating system Wait for data Copy data to user Return ok Process blocks Deliver SIGIO Process continues recvfrom() System call Signal Handler

Asynchronous I/O aio_read() No datagram ready datagram ready Copy datagram Copy complete Signal handler Process datagram System call ApplicationOperating system Wait for data Copy data to user Return ok Process continues return

select() call Allows a process to wait for an event to occur on any one of its descriptors. Types of event –ready for read –ready for write –Exception condition

select() call int select( int maxfdp1,/* max. fd + 1 */ fd_set *readfds, /* read ready? */ fd_set *writefds, /* write ready? */ fd_set *exceptfds, /* exceptions? */ struct timeval *timeout); struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */ }

struct fd_set Set of descriptors that we want to wait on for events. Typically holds 256 descriptor states. Manipulation macros –void FD_ZERO(fd_set *fds) –void FD_SET (int fd, fd_set *fds) –void FD_CLR (int fd, fd_set *fds) –void FD_ISSET(int fd, fd_set *fds)

Non-forking Concurrent Server fdset rdset, wrset; int listenfd, connfd1, connfd2; int maxfdp1; ……… Connection establishment etc. ……… /* initialize */ FD_ZERO(&rdset); FD_ZERO(&wrset);

for( ;; ) { FD_SET(connfd1, &rdset); FD_SET(connfd2, &wrset); FD_SET(listenfd, &rdset); maxfdp1 = max(connfd1, connfd2, listenfd) + 1; /* wait for some event */ Select(maxfdp1, &rdset, &wrset, NULL, NULL); if( FD_ISSET(connfd1, &rdset) ) { Read data from connfd1… } if( FD_ISSET(connfd2, &wrset) ) { Write data to connfd2… } if( FD_ISSET(listenfd, &rdset) { Process a new connection… }

High resolution timer! Select can be used as a millisecond resolution timer. select ( 0, NULL, NULL, NULL, &timeval) Usual sleep (…) call has resolution of seconds.

Socket Options

Managing socket options – 3 ways getsockopt() and setsockopt() fcntl() ioctl()

getsockopt() and setsockopt() int getsockopt( int sockfd, int level, /* SOL_SOCKET, IPPROTO_IP, IPPROTO_TCP etc */ int optname, /* option name */ void *opt­val, /* option value */ socklen_t *optlen); /* data length of option*/ int setsockopt( int sockfd, int level, int optname, const void *optval, socklen_t optlen);

Some socket options SO_BROADCAST - enable socket for sending broadcast SO_KEEPALIVE – regularly probes on inactive TCP connection. SO_LINGER – linger till all data is sent before returning from close() on a TCP connection. SO_RCVBUF/ SO_SNDBUF – size of receive/send buffers on socket. SO_RCVTIMEO/SO_SNDTIMEO – place timeout on receive/send operation.

fcntl() int fcntl(int fd, int cmd, long arg); Miscellaneous file control operations –Non-blocking I/O (O_NONBLOCK, F_SETFL) –Signal-driven I/O (O_ASYNC, F_SETFL) –Set socket owner (F_SETOWN)