0

In pset6(server.c), when responding to client(browser),

we use the function "dprintf", but why do we put the "dprintf" in the "if" ocndition, and call "continue" when

"dprintf" fails? What is the meaning of "continue", why do we need that?? And do we have to call function

"write" each time we respond to client?

Thanks!!

2

The keyword continue simply skips the current iteration of the loop. Of course you don't wanna continue the process of responding to the client if part of this process failed.

do we have to call function "write" each time we respond to client?

Per the man pages of write (section 2)

ssize_t write(int fd, const void *buf, size_t count);

DESCRIPTION
       write()  writes  up  to  count bytes from the buffer pointed buf to the
       file referred to by the file descriptor fd.

In the distribution code, there are 3 arguments passed to write (i.e., cfd, body, and size). This basically means that write writes size bytes from body into cfd.

The first argument, cfd, represents the file descriptor that represents the connection between your program (the web server) and your client (e.g., the browser, telnet, etc.). Execute man 2 write in the terminal for more information about this function!

5
  • After reading the man page, I still don't fully understand. Am I in the right track(about the following question)? When I implement "validate request-line", and "ensure path exists(and readable)", should I use "line" or "request" for the second argument(const void *buf) of "write" ? And should I use "octets" for the third argument(size_t count) of "write" ?
    – Y_C
    Feb 24 '15 at 16:52
  • @Yung-ChengHsu why would you use write to validate the request-line or ensure the path exists?
    – kzidane
    Feb 24 '15 at 22:54
  • Well, I'm not really sure when to use "write", since it says like "• if method is not GET , respond to the browser with 405 Method Not Allowed" for validate request-line and "Ensure that path actually exists. Respond to the browser with 404 Not Found if not!" for checking the existence in the pset6 pdf file. They both mentioned "respond to the browser", I just want to know when to use "write" after "dprintf", since there's "write" when we "respond to client". Isn't it responding with the same thing?
    – Y_C
    Feb 26 '15 at 0:59
  • @Yung-ChengHsu if I may ask, did you read the whole specs? Did you read the whole distribution code?
    – kzidane
    Feb 26 '15 at 10:20
  • Yes, I did. but I just read it again a few hours ago, and suddenly I realize I have got the wrong idea. Now, I have finished pset6, and thanks for your comments and answers!
    – Y_C
    Feb 27 '15 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .