Advanced UNIX programming

Slides:



Advertisements
Similar presentations
Linux Serial Programming for POSIX Operating Systems
Advertisements

Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Nonblocking I/O Blocking vs. non-blocking I/O
Terminal I/O POSIX termios Two terminal I/O modes Canonical and non-canonical Getting and setting terminal attributes Terminal window size: struct winsize.
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 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.
UDP and Multi-thread Socket Programming
Terminal Control operating systems. Terminal Control may seem like an arcane subject, but … It illustrates the relationship between devices and files.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Generic Transport Service Primitives Listen –notify Transport layer a call is expected Connect –establish Transport layer connection Send (or Write) Receive.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
Terminal Control Many special files represent devices that are platform dependent, making standardization difficult POSIX standards committee decided to.
Tutorial 8 Socket Programming
1 Generic Transport Service Primitives Listen –notify Transport layer a call is expected Connect –establish Transport layer connection Send (or Write)
Dynamic visualizations On ‘non-canonical’ keyboard-input and terminal escape-sequences for visualization effects.
Michener’s Algorithm An efficient scheme for drawing circles (and filling circular disks) on a raster graphics display.
Linux game programming An introduction to the use of interval timers and asynchronous input notifications.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
ECE 4110 – Internetwork Programming Client-Server Model.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
Chapter 5. Connection Controls. Device == File ? Filenames Properties permission bits system call – open, read, write, lseek, close, stat.
Signal-Driven I/O Concepts and steps for using signal-driven I/O
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 5 Acknowledgements: The syllabus and power point presentations are modified versions.
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.
Chapter 2 Applications and Layered Architectures Sockets.
The tty Interface An introduction to “systems programming” in the Linux environment.
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.
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.
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.
Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 25 Acknowledgements: The syllabus and power point presentations are modified versions.
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
Implementing ‘noecho’ Programming details regarding the Linux implementation for ‘struct termios’ objects.
Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified.
Today’s topic: UDP Reliable communication over UDP.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 9 Acknowledgements: The syllabus and power point presentations are modified versions.
Review: –Concurrent server and multiplexed server How they work? Which one is better?
Today’s topics Signals and how to control the program behavior in handling signals. Terminal I/O.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
UNIX Sockets Outline UNIX sockets CS 640.
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.
Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 28 Acknowledgements: The syllabus and power point presentations are modified versions.
1 Dimension of Server Designs r Iterative vs Concurrent r Connection-oriented vs. connectionless r Stateful and stateless m Constrained by application.
Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 17 Acknowledgements: The syllabus and power point presentations are modified versions.
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.
1 UDP Sockets Programming Creating UDP sockets.Creating UDP sockets. –Client –Server Sending data.Sending data. Receiving data.Receiving data. Connected.
Exercise ● Exercise 4.15: Write a version of mkdir which supports the - p option. Due by class 2/23....
I/O Multiplexing.
Socket Option.
Advanced UNIX progamming
CHAPTER 8 ELEMENTARY UDP SOCKETS
Network Programming CSC- 341
Lecture 4 Socket Programming Issues
UDP Sockets Programming
Lecture 11 Overview.
Advanced UNIX progamming
Advanced UNIX 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,
Advanced UNIX programming
Advanced UNIX programming
Presentation transcript:

Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 37 Acknowledgements: The syllabus and power point presentations are modified versions of those by T. Baker and X. Yuan

Announcements Project Quiz Monday Presentations next week Demo next week Quiz Monday Monday’s and today’s lecture material Monday’s lecture material included in finals

Week 14 Topics Signals and threads Terminal I/O Signal driven I/O APUE chapter 11 Signal driven I/O UNP chapter 22 Non-blocking I/O UNP chapter 15

Terminal I/O Canonical mode (not our focus) Non-canonical mode The default mode, input line by line Non-canonical mode Input characters are not assembled termios structure tcgetattr and tcsetattr Turning on the non-canonical mode

termios structure struct termios Stores all the characteristics of a terminal device that we can examine and change termios.h { tcflag_t c_iflag; /* input flag */ tcflag_t c_oflag; /* output flag */ tcflag_t c_cflag; /* control flags */ tcflag_t c_lflag; /* local flags */ cc_t c_cc[NCCS]; /* control characters */ };

Functions to get and set the fields in the termios structure #include <termios.h> int tcgetattr(int fildes, struct termios *termios_p) int tcsetattr(int fildes, int optional_actions, const struct termios *termios_p) optional_actions TCSANOW TCSADRAIN TCSAFLUSH

Turn on the noncanonical mode Unset the ICANON flag in c_lflag myterm.c_lflag & = ~ICANON When will a read return using the noncanonical mode for input? Number of characters (VMIN) Time (VTIME) Specified in the c_cc field c_cc[VMIN] = ???, c_cc[VTIME] = ??? VMIN > 0, VTIME > 0 VMIN = 0, VTIME > 0 VMIN > 0, VTIME = 0 VMIN = 0, VTIME = 0 See example1.c and example2.c

Signal driven I/O The kernel raises a signal when something happens to a file descriptor Signal driven I/O for sockets Establish a signal handler for SIGIO Set the socket owner Enable signal-driven I/O for the socket

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

Non-blocking I/O For input operations For output operations For accept read, recv, recvfrom, etc. If the operation cannot be satisfied, return with an error of EWOULDBLOCK For output operations write send, sendto, etc. If no buffer space, return with an error of WOULDBLOCK For accept If a new connection is not available, return with an error of EWOULDBLOCK For connect If the connection cannot be established right away, EINPROGRESS is returned