Signal-Driven I/O Concepts and steps for using signal-driven I/O

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.
IEG4180 Tutorial 3 Shaoquan Zhang. Announcement The deadline of the project 1 is extended to 11pm, 12/02/2011 Follow the requirement of the marking scheme.
Out-of-Band Data© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science.
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.
The ‘fasync()’ driver-method Two viewpoints on implementing asynchronous notification: the application’s and the driver’s.
Computer Networks Sockets. Sockets and the OS F An end-point for Internet connection –What the application “plugs into” –OS provides Application Programming.
I/O Multiplexing© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
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.
Lecture 8 UDP Sockets & I/O Multiplexing
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
IP Multiplexing Ying Zhang EECS 489 W07.
I/O Systems ◦ Operating Systems ◦ CS550. Note:  Based on Operating Systems Concepts by Silberschatz, Galvin, and Gagne  Strongly recommended to read.
ECE 4110 – Internetwork Programming Client-Server Model.
Hands On Networking Socket Programming Ram P Rustagi, ISE Dept Abhishek Gupta, ISE Dept Laxmi Kuber, MCA Dept June 28-30, 2012.
Elementary TCP Sockets
Socket programming. Sockets are a protocol independent method of creating a connection between processes. Sockets can be either: connection based or connectionless:
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.
Network Programming Eddie Aronovich mail:
7.9 TCP Socket Options 7.10 SCTP Socket Options 7.11 fcntl Function 7.12 Summary 報告者 : 梁凱鈞.
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 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.
CE Operating Systems Lecture 13 Linux/Unix interprocess communication.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
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,
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.
Client/Server Socket Programming Project
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.
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
1 Socket Options getsockopt and setsockopt functions Check options and obtain default values Generic socket options IPv4 socket options IPv6 socket options.
TCP Client-Server Example
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.
1 Dimension of Server Designs r Iterative vs Concurrent r Connection-oriented vs. connectionless r Stateful and stateless m Constrained by application.
1 ioctl Function ioctl function get_ifi_info function ARP cache operations: eg. Print H/W addresses.
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.
Sockets API Developing Applications using the Sockets API.
SOCKET PROGRAMMING Presented By : Divya Sharma.
IPv4 socket option Level => IPPROTO_IP
Module 12: I/O Systems I/O hardware Application I/O Interface
I/O Multiplexing.
Socket Option.
Operating Systems Review ENCE 360.
Beyond HTTP Up to this point we have been dealing with software tools that run on browsers and communicate to a server that generates files that can be.
Review: TCP Client-Server Interaction
CSCI 315 Operating Systems Design
Lecture 4 Socket Programming Issues
UDP Sockets Programming
CGS 3763 Operating Systems Concepts Spring 2013
I/O Systems I/O Hardware Application I/O Interface
Operating System Concepts
CS703 - Advanced Operating Systems
Socket Programming.
Advanced UNIX programming
TA: Donghyun (David) Kim
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
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,
Module 12: I/O Systems I/O hardwared Application I/O Interface
Presentation transcript:

Signal-Driven I/O Concepts and steps for using signal-driven I/O UDP echo server using signal-driven I/O Readings UNP Section 6.2, Ch25 Last time we studied nonblocking I/O, where functions like read/write/accept/connect will return immediately if socket is not “ready”. Today we will discuss another advanced form of I/O---signal-driven I/O. We will discuss the concepts of signal-driven I/O, and the steps we must take into develop signal-driven I/O programs. We will also illustrate the concepts and steps of signal-driven I/O by developing a UDP echo server. We emphasize here that, like nonblocking I/O, signal-driven I/O does not only apply to socket, it applies to other disk or other device access.

Motivation Efficiently detecting an asynchronous event (arrival of a connection, arrival of a message, etc) is difficult. Blocking IO: can block for a long time Nonblocking IO: do not block for a long time, but must keep polling – tedious How do we deal with other types of asynchronous events? E.g. input from keyboard? Using interrupt Corresponding to this, we have signal driven IO In signal-driven I/O, we do not directly try to read from a socket. Instead, we wait for the signal SIGIO, which will be generated by the kernel when something happens to a socket descriptor. When we receive the signal, then we will read data from the descriptor. In order for us to use signal-driven I/O, we must take a few steps. The first step is to associate a signal handler with the signal SIGIO. We are familiar with this part. We can use functions signal or sigaction to set a handler for SIGIO. The second step is to set the socket owner. Essentially, we let the system know where the signal SIGIO should be delivered. The last step is to enable the signal-driven I/O for the socket, that is, changing the socket from the default blocking socket to signal-driven socket. We will detail the last two steps in the following slides.

Signal-driven I/O The kernel raises a signal (SIGIO) when something happens to a file descriptor Three steps to use signal-driven I/O with sockets Establish a signal handler for SIGIO Functions signal/sigaction Set the socket owner fcntl with command F_SETOWN Enable signal-driven I/O for the socket fcntl with command O_SETFL (turn on O_ASYNC) ioctl with request FIOASYNC In signal-driven I/O, we do not directly try to read from a socket. Instead, we wait for the signal SIGIO, which will be generated by the kernel when something happens to a socket descriptor. When we receive the signal, then we will read data from the descriptor. In order for us to use signal-driven I/O, we must take a few steps. The first step is to associate a signal handler with the signal SIGIO. We are familiar with this part. We can use functions signal or sigaction to set a handler for SIGIO. The second step is to set the socket owner. Essentially, we let the system know where the signal SIGIO should be delivered. The last step is to enable the signal-driven I/O for the socket, that is, changing the socket from the default blocking socket to signal-driven socket. We will detail the last two steps in the following slides.

Set Socket Owner Function fcntl with command F_SETOWN fcntl(int fd, int cmd, … /* int arg*/) Set process ID or process group ID to receive SIGIO and SIGURG signals Arg > 0: process ID == arg Arg < 0: process group ID == |arg| We use the function fcntl to set the socket owner. It is achieved via the command F_SETOWN. The command F_SETOWN set the process ID or process group ID to receive SIGIO and SIGURG signals. The third parameter arg informs the kernel the process ID or the group ID, depending on the value of arg. When arg is positive, it specifies the process ID. The following line of code shows how to use fcntl to set socket owner in a program. fcntl(sockfd, F_SETOWN, getpid());

Enable Signal-Driven I/O for Socket Function fcntl with command F_SETFL Turn on O_ASYNC Function ioctl with request FIOASYNC int flag; flag = fcntl(sockfd, F_GETFL, 0); fcntl(sockfd, F_SETFL, flag | O_ASYNC); In order to enable signal-driven I/O, we can use either fcntl or ioctl. int on = 1; ioctl(sockfd, FIOASYNC, &on);

Complication of Signal-Driven I/O Signals are not queued when they are blocked When SIGIO is blocked, at most one SIGIO signal will be pending even if two pieces of data arrive No one to one mapping between number of signals and arrived data In handler of SIGIO, we need to handle all arriving data Read until there is no data (how?) Nonblocking I/O needs to be used with signal-driven I/O One particular problem that we need to pay attention when we use signal-driven I/O is, recall that, when a signal is blocked, the kernel only maintain one instance of a signal, even if it is generated multiple times. What is the consequence for socket programming? In signal-driven I/O, when SIGIO is blocked, at most one SIGIO will be pending in the kernel even if more than one packet arrive. This means that, when we start to read data from socket after we have received the signal SIGIO, we must not make any assumption about the amount of that data that is in the receive buffer. We need to continue read until there is no data left in the receive buffer. However, if we are using a blocking socket, we will be blocked when we try to read and there is no data in the receive buffer. So how we should handle this situation? Well, we need to use signal-driven I/O together with nonblocking I/O.

When is SIGIO raised? For UDP sockets For TCP sockets A datagram arrives An error occurs For TCP sockets A connection request has completed A disconnect request has been initiated A disconnect request has completed Half of a connection has been shut down Data has arrived Data has been sent Too many SIGIOs for a TCP socket – rarely used listening socket We said that when something happens on a socket descriptor, the signal SIGIO will be generated by the kernel. So what is “something”? Or when is SIGIO raised? It depends on the transport layer protocol we are using. For UDP, two conditions can trigger the generation of the SIGIO signal: a datagram has arrived, or some error has occurred. For TCP, it is much complicated. Many conditions can trigger the generation of signal SIGIO. For example, …. For this reason, signal-driven I/O is rarely used for TCP sockets. One exception is listening socket, given that the only condition to trigger SIGIO is when a connection has been established.

Echo Server with Signal-Driven I/O Examples udp_echo_server.cpp and udp_echo_client.cpp A particular use of signal-driven I/O is NTP (network time protocol) Time sensitive. A server needs to record the accurate arrival time of a datagram and return to client.

Summary of I/O models Blocking Nonblocking Multiplexed Signal driven Asynchronous

Blocking IO

Nonblocking IO

I/O Multiplexing

Signal driven

Asynchronous IO