Signals and Threads - Advanced Unix Programming - Lecture Slides, Slides of Computer Programming

Some concept of Advanced Unix Programming are Address Structure, Basic Thread Functions, Client-Server Design, Network Programming, Signals and Thread, Thread-Specific Data, Unix File System, Reliable Communication. Main points of this lecture are: Signals and Threads, Terminal, Signal Driven, Non-Blocking, Canonical Mode, Non-Canonical Mode, Default Mode, Input Line By Line, Input Characters, Assembled

Typology: Slides

2012/2013

Uploaded on 04/29/2013

parmita
parmita 🇮🇳

4.7

(17)

183 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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
Docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Signals and Threads - Advanced Unix Programming - Lecture Slides and more Slides Computer Programming in PDF only on Docsity!

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

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

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

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

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