[cs631apue] final project graded

Jan Schaumann jschauma at stevens.edu
Fri Dec 21 12:36:08 EST 2012


Hello,

I've graded your final projects, and each of you should have received a
grade.  If you have not received a grade, then you should have received
an email from me asking for clarification on how to run your program.
If you have not received either email from me, please let me know ASAP.

Here are a few things many of you got wrong that are worth noting:

- malloc(3) can fail - check your return status on _all_ functions

- you cannot read the file to serve into a buffer and then write it to a
  socket -- this doesn't work for large files, as you have a fixed size
  buffer (and/or not enough memory, see above); instead, you need to
  loop and write the file little by little.  From our earlier discussion
  around the cp(1) command, you know how to identify the most efficient
  I/O buffer size, right?

- all HTTP requests require an empty line before you can respond to
  them;  that is, after you read the first line, you cannot start
  responding, but you must read another line (which may be a client
  header, if so, read another etc. until you encounter an empty line);
  without that, you cannot implement the If-Modified-Since header or
  POST

- when processing CGI requests, you need to tokenize the URI, since a
  GET request for a CGI may append parameters after the file name:

  GET /cgi-bin/mumble.cgi?param1=value&param2=value2 HTTP/1.0

- you need to verify the command-line arguments; if a user specifies
  "bob" as the port to bind to and "yellow" as the IP address, you
  probably shouldn't proceed...

- error messages to the user need to be explicit in saying what went
  wrong; just saying "error" and displaying the usage is not helpful

- when using a logfile, do not open and close the file for every single
  request you're logging; think about an average webserver processing a
  few hundred requests per second: opening and closing the file will
  cause tremendous overhead.  Instead, open the log file at program
  start, close at exit.

- when expanding ~ to the user's home directory, it's a good idea to not
  hardcode "/home", but instead get the user's home directory from
  getpwnam(3)

- when creating the log file, make sure the permissions are reasonable
  (ie the owner can write to it)

- if you don't use getopt(3), your command-line processing is likely to
  be broken; also, you are inflating the number of lines of code you
  wrote (and which are thus likely to be buggy)

- if you don't use daemon(3), your daemonization is likely to be broken;
  also, you are inflating the number of lines of code you wrote (and
  which are thus likely to be buggy)

Remember: the less code you write yourself, the better.  If you've
already written code that (you think) works, ripping it out and
replacing it with existing library calls is still the right thing to do.

Finally, I hope you all learned a bit about writing a network service
and about how HTTP works.

-Jan


More information about the cs631apue mailing list