1 / 10

Advanced UNIX programming

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 Presentations next week Demo next week Quiz Monday

kiara-foley
Download Presentation

Advanced UNIX programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 • Monday’s and today’s lecture material • Monday’s 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_cc[NCCS]; /* control characters */ };

  6. 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

  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_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

  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

More Related