Advanced UNIX programming - PowerPoint PPT Presentation

About This Presentation
Title:

Advanced UNIX programming

Description:

Title: Advanced UNIX progamming Author: asriniva Last modified by: asriniva Created Date: 6/5/2002 8:34:37 PM Document presentation format: On-screen Show – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 11
Provided by: asri9
Learn more at: http://www.cs.fsu.edu
Category:

less

Transcript and Presenter's Notes

Title: Advanced UNIX programming


1
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
2
Announcements
  • Project
  • Presentations next week
  • Demo next week
  • Quiz Monday
  • Mondays and todays lecture material
  • Mondays lecture material included in finals

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

4
Terminal I/O
  • Canonical mode (not our focus)
  • 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

5
termios structure
  • struct termios
  • Stores all the characteristics of a terminal
    device that we can examine and change
  • termios.h
  • struct termios
  • 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_ccNCCS / control characters
    /

6
Functions to get and set the fields in the
termios structure
  • include lttermios.hgt
  • 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

7
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_ccVMIN ???, c_ccVTIME ???
  • VMIN gt 0, VTIME gt 0
  • VMIN 0, VTIME gt 0
  • VMIN gt 0, VTIME 0
  • VMIN 0, VTIME 0
  • See example1.c and example2.c

8
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

9
When is SIGIO raised?
  • For UDP 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

10
Non-blocking I/O
  • For input operations
  • 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
Write a Comment
User Comments (0)
About PowerShow.com