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.

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Nonblocking I/O Blocking vs. non-blocking I/O
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.
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.
Lecture 12 Overview. UDP Connected mode A UDP socket can be used in a call to connect() This simply tells the O.S. the address of the peer No handshake.
Lecture 16 Overview. Creating a TCP socket int bind(int sockfd, const struct sockaddr *myaddr, socklen_t addrlen); int mysock; struct sockaddr_in myaddr;
Computer Networks Sockets. Sockets and the OS F An end-point for Internet connection –What the application “plugs into” –OS provides Application Programming.
TDC561 Network Programming Camelia Zlatea, PhD Week 3: Unix Asynchronous Events; Signals and Alarms API.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Threads CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent University.
Advanced Sockets Amit Mondal TA, Intro to Networking Jan 22, 2009 Recital 3 Introduction to Networking Instructor: Prof. Aleksandar Kuzmanovic.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Sockets and concurrency Spring 2010, Recitation 3 Your Awesome TAs.
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.
CS4514 Assignment 2 Help Session – Data Link Layer Client and Server Processes Speaker: Hao Shang Date: Nov. 11th, 2004.
1 Nonblocking I/O Nonblocking reads and writes Buffers enabling overlapped nonblocking I/O Nonblocking connect.
Non-blocking I/O int flags; int fd; /* file descripter */ void main() { fd = open(“myfile.txt”, R_ONLY); if ((flags = fcntl(fd, F_GETFL, 0)) < 0) /* first.
Network LayerDatalink LayerPhysical LayerNetwork LayerDatalink LayerPhysical Layer ClientServer Framework.
Computer Networks Sockets. Outline F Socket basics F Socket details.
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*
IP Multiplexing Ying Zhang EECS 489 W07.
1 Non-blocking I/O Computing Network Programming.
Signal-Driven I/O Concepts and steps for using signal-driven I/O
Socket Models Different ways to manage your connections.
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.
TELE 402 Lecture 10: Unix domain … 1 Overview Last Lecture –Daemon processes and advanced I/O functions This Lecture –Unix domain protocols and non-blocking.
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.
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
CSCE 515: Computer Network Programming Select Wenyuan Xu Department of Computer Science and Engineering.
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.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
IPC Programming. Process Model Processes can be organized into a parent-child hierarchy. Consider the following example code: /* */
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,
Cs423-cotter1 Concurrency Issues in Client/Server Applications Chapters 15,16, 28.
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)
Today’s topic: UDP Reliable communication over UDP.
Threads versus Events CSE451 Andrew Whitaker. This Class Threads vs. events is an ongoing debate  So, neat-and-tidy answers aren’t necessarily available.
CMPT 471 Networking II Network Programming © Janice Regan,
回到第一頁 Client/sever model n Client asks (request) – server provides (response) n Typically: single server - multiple clients n The server does not need.
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 에서 사용.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
@Yuan Xue CS 283Computer Networks Spring 2013 Instructor: Yuan Xue.
1 UDP Sockets Programming Creating UDP sockets.Creating UDP sockets. –Client –Server Sending data.Sending data. Receiving data.Receiving data. Connected.
Netprog: TCP Sockets1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level.
Mgr inż. Marcin Borkowski UNIX Pipe and FIFO. mgr inż. Marcin Borkowski Waiting for I/O ● Pipes, FIFO's, sockets and stdin usually can not produce data.
More Project 1 and HW 1 stuff! Athula Balachandran Wolfgang Richter
I/O Multiplexing.
Operating Systems Review ENCE 360.
Pertemuan 7 I/O Multiplexing
Review: TCP Client-Server Interaction
Advanced Sockets Introduction to Networking
Lecture 4 Socket Programming Issues
UDP Sockets Programming
Lecture 11 Overview.
Lecture 17 Overview.
Socket Programming.
Daemons & inetd Refs: Chapter 12.
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,
Presentation transcript:

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 (like telnet) –need to be able to handle unexpected situations, perhaps a server that shuts down without warning. –A server that handles both TCP and UDP

2 Example - generic TCP client Input from standard input should be sent to a TCP socket.Input from standard input should be sent to a TCP socket. Input from a TCP socket should be sent to standard output.Input from a TCP socket should be sent to standard output. How do we know when to check for input from each source?How do we know when to check for input from each source?

3 Generic TCP Client STDIN STDOUT TCP SOCKET

4 Options Use nonblocking I/O.Use nonblocking I/O. –use fcntl() to set O_NONBLOCK Use alarm and signal handler to interrupt slow system calls.Use alarm and signal handler to interrupt slow system calls. Use multiple processes/threads.Use multiple processes/threads. Use functions that support checking of multiple input sources at the same time.Use functions that support checking of multiple input sources at the same time.

5 Non blocking I/O use fcntl() to set O_NONBLOCK :use fcntl() to set O_NONBLOCK : int flags; flags = fcntl(sock,F_GETFL,0); fcntl(sock,F_SETFL,flags | O_NONBLOCK); Now calls to read() (and other system calls) will return an error and set errno to EWOULDBLOCK.Now calls to read() (and other system calls) will return an error and set errno to EWOULDBLOCK.

6 while (! done) { if ( (n=read(STDIN_FILENO,…)<0)) if (errno != EWOULDBLOCK) /* ERROR */ else write(tcpsock,…) else write(tcpsock,…) if ( (n=read(tcpsock,…)<0)) if ( (n=read(tcpsock,…)<0)) if (errno != EWOULDBLOCK) /* ERROR */ else write(STDOUT_FILENO,…) else write(STDOUT_FILENO,…)}

7 The problem with nonblocking I/O Using blocking I/O allows the Operating System to put your program to sleep when nothing is happening (no input). Once input arrives the OS will wake up your program and read() (or whatever) will return.Using blocking I/O allows the Operating System to put your program to sleep when nothing is happening (no input). Once input arrives the OS will wake up your program and read() (or whatever) will return. With nonblocking I/O the process will chew up all available processor time!!!With nonblocking I/O the process will chew up all available processor time!!!

8 Using alarms signal(SIGALRM, sig_alrm); alarm(MAX_TIME);read(STDIN_FILENO,…);... alarm(MAX_TIME);read(tcpsock,…);...

9 Alarming Problem What will be the effect on response time ?What will be the effect on response time ? What is the ‘right’ value for MAX_TIME?What is the ‘right’ value for MAX_TIME?

10 Select() The select() system call allows us to use blocking I/O on a set of descriptors (file, socket, …).The select() system call allows us to use blocking I/O on a set of descriptors (file, socket, …). For example, we can ask select to notify us when data is available for reading on either STDIN or a TCP socket.For example, we can ask select to notify us when data is available for reading on either STDIN or a TCP socket.

11 Select() int select( int maxfd, fd_set *readset, fd_set *readset, fd_set *writeset, fd_set *writeset, fd_set *excepset, fd_set *excepset, const struct timeval *timeout); const struct timeval *timeout); maxfd : highest number assigned to a descriptor. weadset : set of descriptors we want to read from. writeset : set of descriptors we want to write to. excepset : set of descriptors to watch for exceptions. timeout : maximum time select should wait

12 struct timeval struct timeval { long tv_usec;/* seconds */ long tv_usec;/* microseconds */ } struct timeval max = {1,0};

13 fd_set Implementation is not importantImplementation is not important Operations to use with fd_set:Operations to use with fd_set: void FD_ZERO( fd_set *fdset); void FD_SET( int fd, fd_set *fdset); void FD_CLR( int fd, fd_set *fdset); int FD_ISSET( int fd, fd_set *fdset);

14 Using select() Create fd_setCreate fd_set clear the whole thing with FD_ZERO clear the whole thing with FD_ZERO Add each descriptor you want to watch using FD_SET.Add each descriptor you want to watch using FD_SET. Call selectCall select when select returns, use FD_ISSET to see if I/O is possible on each descriptor.when select returns, use FD_ISSET to see if I/O is possible on each descriptor.

15 Proxy Web Server You don’t need to handle this situation for project 1 !!!!!!You don’t need to handle this situation for project 1 !!!!!! What if the server does not respond (is slow), the client gets tired of waiting and wants to make a new request?What if the server does not respond (is slow), the client gets tired of waiting and wants to make a new request?