------------------------- Week 06 Notes for CST8165 ------------------------- -Ian! D. Allen - idallen@idallen.ca Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) New in Notes: buffer_overflows.txt deep_indentation.txt header_files.txt Domain Name System (DNS) ------------------------ DNS turns names into IP addresses. Not essential for a raw Internet connection; but, very, very useful. Important Fact: DNS uses (mostly) UDP, not TCP, for queries and responses. Q: What type of IP protocol does DNS use (most of the time)? Q: T/F The choice of DNS transport protocol means a DNS request is automatically retried if it fails. Multiple simultaneous connections --------------------------------- How does Unix/Linux handle multiple simultaneous connections? - if your server process is blocked on an accept() or read(), it can't process other client connections - if your client process is reading your keyboard, it can't display input coming from the server - need to listen to multiple file descriptors at the same time Solutions: A. fork() separate processes to handle each file descriptor - server forks a new child process for each new client connection - client forks into one process for keyboard, one for server socket B. use select() to listen to multiple file descriptors at the same time - no need to fork() C. separate threads fork() and select() are the traditional designs; threads are new Using select(): - the select() system call listens to multiple I/O descriptors all at the same time and unblocks when I/O is possible on any of them - select() I/O descriptors are represented in bit vectors: * FD_ZERO(fd_set *set) -- clears a file descriptor set * FD_SET(int fd, fd_set *set) -- adds fd to the set * FD_CLR(int fd, fd_set *set) -- removes fd from the set * FD_ISSET(int fd, fd_set *set) -- tests to see if fd is in the set http://beej.us/guide/bgnet/output/htmlsingle/bgnet.html#select Write the PDL for this program. In Week 6: 1) I reviewed section on "6.2. select()--Synchronous I/O Multiplexing" in http://beej.us/guide/bgnet/output/htmlsingle/bgnet.html and did a read-through of code that uses the select() syscall. 2) I wrote the PDL for selectserver.c and reworked it (and the code) to reduce the number of indentation levels (as per Lab #04). If you missed the class, more descriptions of how select() works are here: http://www.mksxserver.com/docs/man3/select.3.asp http://www.opengroup.org/onlinepubs/007908799/xsh/select.html http://www.lowtek.com/sockets/select.html http://swoolley.homeip.net/man.cgi/select_tut http://www.developerweb.net/forum/showthread.php?t=2933