Nonblocking I/O Blocking vs. non-blocking I/O Nonblocking input, output, accept, and connect Readings –UNP Ch16 1.

Slides:



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

Socket Programming. Basics Socket is an interface between application and network – Application creates a socket – Socket type dictates the style of communication.
CCNA – Network Fundamentals
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.
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.
UDP and Multi-thread Socket Programming
Computer Networks Sockets. Sockets and the OS F An end-point for Internet connection –What the application “plugs into” –OS provides Application Programming.
Multimedia Networking Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
1 Nonblocking I/O Nonblocking reads and writes Buffers enabling overlapped nonblocking I/O Nonblocking connect.
CSCE 515: Computer Network Programming TCP Details Wenyuan Xu Department of Computer Science and Engineering.
Computer Networks Sockets. Outline F Socket basics F Socket details.
Lecture 8 UDP Sockets & I/O Multiplexing
IP Multiplexing Ying Zhang EECS 489 W07.
UNIX Sockets COS 461 Precept 1.
Server Design Discuss Design issues for Servers Review Server Creation in Linux.
ECE 4110 – Internetwork Programming Client-Server Model.
Sockets and intro to IO multiplexing. Goals We are going to study sockets programming as means to introduce IO multiplexing problem. We will revisit socket.
Hands On Networking Socket Programming Ram P Rustagi, ISE Dept Abhishek Gupta, ISE Dept Laxmi Kuber, MCA Dept June 28-30, 2012.
1 Non-blocking I/O Computing Network Programming.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
Signal-Driven I/O Concepts and steps for using signal-driven I/O
Socket programming. Sockets are a protocol independent method of creating a connection between processes. Sockets can be either: connection based or connectionless:
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.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
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 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.
Advanced Sockets API-II Vinayak Jagtap
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.
UNIX Sockets COS 461 Precept 1. Socket and Process Communication The interface that the OS provides to its networking subsystem application layer transport.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
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.
Review: –Concurrent server and multiplexed server How they work? Which one is better?
1 Socket Options getsockopt and setsockopt functions Check options and obtain default values Generic socket options IPv4 socket options IPv6 socket options.
CMPT 471 Networking II Network Programming © Janice Regan,
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.
1 Dimension of Server Designs r Iterative vs Concurrent r Connection-oriented vs. connectionless r Stateful and stateless m Constrained by application.
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 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
Andrew Hanushevsky: Sendfile() First INFN International School on Architectures, tools and methodologies for developing efficient large scale scientific.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Socket Abstraction and Interprocess Communication
UDP Socket Programming
IPv4 socket option Level => IPPROTO_IP
I/O Multiplexing.
UNIX Sockets COS 461 Precept 1.
Interprocess Communication
CHAPTER 8 ELEMENTARY UDP SOCKETS
Lecture 4 Socket Programming Issues
Socket Abstraction and Interprocess Communication
Advanced UNIX programming
Starting TCP Connection – A High Level View
Socket Abstraction and Interprocess Communication
CSC Advanced Unix Programming, Fall 2015
Socket Abstraction and Interprocess Communication
Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
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 Programming with UDP
Presentation transcript:

Nonblocking I/O Blocking vs. non-blocking I/O Nonblocking input, output, accept, and connect Readings –UNP Ch16 1

Blocking vs. Nonblocking I/O Blocking I/O –When an operation cannot be completed immediately, the process is put into sleep Nonblocking I/O –When an operation cannot be completed immediately, the function return immediately with an error, so the process can proceed accordingly (e.g. elect to do something else). Implications on input, output, accept, and connect 2

Input Operations Functions read, recvfrom, readv, recv, recvmsg Blocking socket –TCP: sleep until some data arrives –UDP: sleep until a UDP datagram arrives Nonblocking socket –Return immediately with an error EWOULDBLOCK, if no data in receive buffer 3

Output Operations Functions write, sendto, writev, send, and sendmsg Blocking socket –TCP: sleep until room is available in send buffer –UDP: does not have socket send buffer. A process can be blocked due to buffering etc in protocol stack. Nonblocking socket –TCP: return immediately with an error EWOULDBLOCK, if no room in send buffer –UDP: send operation cannot be completed due to various reasons 4

Accepting New Connections Function accept Blocking socket –Sleep until some new connections available Nonblocking socket –Return immediately with an error EWOULDBLOCK, if no new connection is available 5

Initiating Outgoing Connections Function connect (for TCP) Blocking socket –Sleep until ACK is received for SYN packet. Nonblocking socket –Return immediately with an error of EINPROGRESS, if connection cannot be established immediately –Note that a connection may be established immediately 6

Making Socket Nonblocking File control function –cmd: F_GETFL and F_SETFL I/O control function –Request: FIONBIO #include int fcntl(int fd, int cmd, … /* int arg */) flag = fcntl(sockfd, F_GETFL, 0); fcntl(sockfd, F_SETFL, flag | O_NONBLOCK); #include int ioctl(int fd, int request, … ) int on = 1 ioctl(sockfd, FIONBIO, (char *)&on); 7

How to Handle Nonblocking I/O A nonblocking function returns immediately, what’s next? Choice 1: Do some other things –A program may not have other things to do Choice 2: keeping on “polling” until success –Waste system resources Choice 3: blocking somewhere until some operation can be performed –select() function 8

Select and Nonblocking I/O When is a socket “ready” for nonblocking I/O? –When data arrives in receive buffer, it is ready for read –When room is available in send buffer, it is ready for write –For server side (accept), when a new connection is available, it is ready for both read and write –For client side (connect), when a connection is established, it is ready for write; when a connection cannot be established, it is ready for both read and write So how you know if a connection has been established successfully or not getsockopt to retrieve SO_ERROR (0 -> success) 9

Blocking and Nonblocking Echo Client Blocking echo client –echo_client_select.cpp Nonblocking echo client –echo_client_nonblocking.cpp 10

Pros and Cons of Nonblocking I/O Advantage –Light overhead, high performance Disadvantages –Much more complicated –Buffer needs to be maintained by application program if message needs to be forwarded from one socket to another Cannot guarantee all writes complete –Other complications like connect Use concurrent and multiplexed design instead of nonblocking I/O, if possible –Under rare condition, select() and blocking accept() not work well –Client connect, server select, client abort and RST sent, RST arrives and connection removed, server accept 11