web_child_r.c 598 B

123456789101112131415161718192021222324252627
  1. #include "unp.h"
  2. #include "readline_r.h"
  3. #define MAXN 16384 /* max #bytes that a client can request */
  4. void
  5. web_child(int sockfd)
  6. {
  7. int ntowrite;
  8. ssize_t nread;
  9. char line[MAXLINE], result[MAXN];
  10. Rline rline;
  11. readline_rinit(sockfd, line, MAXLINE, &rline);
  12. for ( ; ; ) {
  13. if ( (nread = Readline_r(&rline)) == 0)
  14. return; /* connection closed by other end */
  15. /* line from client specifies #bytes to write back */
  16. ntowrite = atol(line);
  17. if ((ntowrite <= 0) || (ntowrite > MAXN))
  18. err_quit("client request for %d bytes", ntowrite);
  19. Writen(sockfd, result, ntowrite);
  20. }
  21. }