[关闭]
@Radon 2014-12-25T02:07:40.000000Z 字数 1487 阅读 1693

Homework 16 & 17

1100012749


Homework 16

9.15

Request Block size (decimal bytes) Block header (hex)
malloc(3) 8 0x9
malloc(11) 16 0x11
malloc(20) 24 0x19
malloc(21) 32 0x21

9.16

都是16

9.17

  1. static char * cur = heap_listp;
  2. static void *find_fit(size_t asize) {
  3. /* Next fit search */
  4. void *bp = cur;
  5. while(GET_ALLOC(HDRP(bp)) || GET_SIZE(HDRP(bp)) < asize) {
  6. bp = (GET_SIZE(HDRP(bp)) == 0) ? heap_listp : NEXT_BLKP(bp);
  7. if (bp == cur) return NULL;
  8. }
  9. cur = NEXT_BLKP(bp);
  10. return bp;
  11. }

9.19

  1. a
  2. d
  3. b

Homework 17

11.6

A.
void doit(int fd)中,sscanf(buf, "%s %s %s", method, uri, version);下加printf("%s %s %s\n", method, uri, version);
read_requesthdrs(rio_t *rp)按如下修改:

  1. void read_requesthdrs(rio_t *rp)
  2. {
  3. char buf[MAXLINE];
  4. do{
  5. Rio_readlineb(rp, buf, MAXLINE);
  6. printf("%s", buf);
  7. }while(strcmp(buf, "\r\n"));
  8. return;
  9. }

B.

  1. GET / HTTP/1.1
  2. Host: localhost:12345
  3. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:32.0) Gecko/20100101 Firefox/32.0
  4. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  5. Accept-Language: en-US,en;q=0.5
  6. Accept-Encoding: gzip, deflate
  7. Connection: keep-alive
  8. Cache-Control: max-age=0

C. HTTP/1.1

D.
User-Agent: 标识生成请求的浏览器或其他客户程序
Accept: 浏览器或者其他客户程序能处理的MIME类型
Accept-Encoding: 可以接受的编码方案
Accept-Language: 可以接受的语言;

11.7

  1. void get_filetype(char *filename, char *filetype)
  2. {
  3. if (strstr(filename, ".html"))
  4. strcpy(filetype, "text/html");
  5. else if (strstr(filename, ".gif"))
  6. strcpy(filetype, "image/gif");
  7. else if (strstr(filename, ".jpg"))
  8. strcpy(filetype, "image/jpeg");
  9. else if(strstr(filename, ".mpg") || strstr(filename, ".mp4"))
  10. strcpy(filetype, "video/mpeg");
  11. else
  12. strcpy(filetype, "text/plain");
  13. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注