1 / 27

CS 241 Section (12/3/10)

CS 241 Section (12/3/10). Announcements. No class on Monday TA review session: Dec. 8, 2010 – in class HW2 due date: Dec. 8, 2010 - 11:00 am No late submissions MP8 due date: Dec. 8, 2010 – 11:59 pm Finals: Dec. 16, 2010 – 8:00 am. In section today. MP8 Overview UNIX File Systems

carys
Download Presentation

CS 241 Section (12/3/10)

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. CS 241 Section (12/3/10)

  2. Announcements • No class on Monday • TA review session: Dec. 8, 2010 – in class • HW2 due date: Dec. 8, 2010 - 11:00 am • No late submissions • MP8 due date: Dec. 8, 2010 – 11:59 pm • Finals: Dec. 16, 2010 – 8:00 am

  3. In section today • MP8 Overview • UNIX File Systems • Directories • Links

  4. MP8 Overview

  5. What is the MP about? • Implement a multi-threaded web server • Web client: browser / wget / telnet • Server should respond to client requests with local pages (from ./pages/ folder)

  6. Running the server • Run the web server • The server listens on the port specified • Choose a port between 1024 and 32000 Port #

  7. Testing the server • Run the web client • wget • Browser • Go to address: • Server name (linux3.ews.illinois.edu) is obtained from the hostname command

  8. MP Task I - Listen • Your server should listen to the port# (specified in argv[1]) for incoming connections • Helper function: newServerSocket(), acceptSocket() • Your server must handle multiple connections at the same time • Every incoming connection spawns a new thread to handle the request

  9. Task II – Receive HTTP Request • HTTP request sent by wget • Function for extracting file name from request • char* getFileNameFromHTTPRequest(void *vptrRequest, size_t length); • All files served from web server root directory • ./pages/ directory

  10. Task III – HTTP 1.1 Response • If the file exists the response starts with: • Function for building the response • HTTPResponse getResponseString(char *sContentType, void *vptrContent, size_t iContentLength);

  11. Task III – HTTP 1.1 Response • If the file does NOT exist the response starts with: • Function for building the response • HTTPResponse getFileNotFoundResponseString()

  12. Task III – HTTP 1.1 Response • If the request is NOT GET the response starts with: • Function for building the response • HTTPResponse getNotImplementedResponseString()

  13. Task III – HTTP 1.1 Response • If the browser request for / • The web server should list all the files in the root directory (./pages/ directory) • ONLY the files • Function for building an HTML page with list of files • char *getHTMLOfDirectoryList(char **fileNames); • Build Response with getResponseString()

  14. Last Task – Sending the Response • We have a HTTP response ready in a HTTPResponse struct: • Use send() to send the vptrResponse back • free vptrResponse after send()

  15. Reading a Directory

  16. Directory reading functions #include <dirent.h> Open the directory DIR *opendir(const char *dirname); Close the directory int closedir(DIR *dirp); Read the directory struct dirent *readdir(DIR *dirp);

  17. What’s in a directory entry? struct dirent Member Fields char d_name[256] Null-terminated file name ino_t d_ino inode number unsigned char d_reclen Length of this record unsigned char d_type Type of file (DT_REG, DT_DIR, DT_FIFO, DT_SOCK, DT_CHR, DT_BLK, DT_UNKNOWN)

  18. Example • Use opendir and readdir to print all the filenames in the current directory: #include <dirent.h> … DIR *dir; struct dirent *entry; dir = opendir(“.”); while(entry = readdir(dir)){ printf(“%s\n”,entry->d_name); } closedir(dir); • Remember to include error checking!!

  19. Links

  20. Links • Hard Link • Directory Entry e.g. all regular files • Symbolic Link (Soft Link) • Special file, serves as a reference to another file

  21. Hard Link Example Command Line ln /dirA/name1 /dirB/name2 C Code Segments if (link("/dirA/name1", "/dirB/name2") == -1) perror("Failed to make a new link in /dirB");

  22. Hard Link Example (contd) Q: What happens if /dirA/name1 is deleted and recreated?

  23. Hard Link Example (contd) A:/dirA/name1 and /dirB/name2 are now two distinct files.

  24. Soft Link Example Command Line ln –s /dirA/name1 /dirB/name2 C Code Segments if (symlink("/dirA/name1", "/dirB/name2") == -1) perror("Failed to create a symbolic link in /dirB");

  25. Soft Link Example (contd) Q: What happens if /dirA/name1 to is deleted and recreated?

  26. Soft Link Example (contd) A:/dirA/name1 has a different inode, but /dir/name2 still links to it.

  27. Link number • The link number (the st_nlink field in stat) tells how many directory entries link to this inode. The link number is: • Set to 1 when a file is created • Incremented when link is called • Decremented when unlink is called • The link number appears in the second column of the output of ls –l. Try it! • The link number only counts hard links, not soft links.

More Related