CS144Lab/writeups/lab0.md
2023-02-16 09:26:38 +00:00

110 lines
3.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Lab 0 Writeup
=============
My name: Catfood
My SUNet ID: 998244353
I collaborated with: An orange cat
This lab took me about `2` hours to do.
My secret code from section 2.1 was: `294080`
- Optional: I had unexpected difficulty with: [打字的手速太慢telnet会超时]
- Optional: I think you could make this lab better by: [describe]
- Optional: I was surprised by: [describe]
- Optional: I'm not sure about: [describe]
实现细节描述
============
2.1.2
```
➜ sponge git:(lab0-startercode) ✗ telnet cs144.keithw.org http
Trying 104.196.238.229...
Connected to cs144.keithw.org.
Escape character is '^]'.
GET /hello HTTP/1.1
Host: cs144.keithw.org
Connection: close
HTTP/1.1 200 OK
Date: Tue, 14 Feb 2023 14:17:29 GMT
Server: Apache
Last-Modified: Thu, 13 Dec 2018 15:45:29 GMT
ETag: "e-57ce93446cb64"
Accept-Ranges: bytes
Content-Length: 14
Connection: close
Content-Type: text/plain
Hello, CS144!
Connection closed by foreign host.
```
2.1.3:
```
➜ sponge git:(lab0-startercode) ✗ telnet cs144.keithw.org http
Trying 104.196.238.229...
Connected to cs144.keithw.org.
Escape character is '^]'.
GET /lab0/998244353 HTTP/1.1
Host: cs144.keithw.org
Connection: close
HTTP/1.1 200 OK
Date: Tue, 14 Feb 2023 14:18:54 GMT
Server: Apache
X-You-Said-Your-SunetID-Was: 998244353
X-Your-Code-Is: 294080
Content-length: 113
Vary: Accept-Encoding
Connection: close
Content-Type: text/plain
Hello! You told us that your SUNet ID was "998244353". Please see the HTTP headers (above) for your secret code.
Connection closed by foreign host.
```
2.2:
学校的邮件系统比较智障,做不了
2.3:
```
➜ sponge git:(lab0-startercode) ✗ telnet localhost 9090
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
fuck
lalal
Connection closed by foreign host.
➜ sponge git:(lab0-startercode) ✗ netcat -v -l -p 9090
Listening on 0.0.0.0 9090
Connection received on localhost 33706
fuck
lalal
```
3.4:
他的提示没啥用但是doxygen里面有个例子可以直接看那个例子。
地址可以直接放域名,`Address(host, protocol)`这个重载是可以DNS查询的因此直接用就行然后TCP socket`connect->write->loop read`就好了。
4:
Buffer开了一个STL的`deque`感觉是最适合做这种buffer的容器了能够前后插入删除、常数级随机访问、动态调整空间非常棒的性质。数据类型用的是`char`byte方便调整。
write接口没啥东西控制一下不要超出空间就行。
read接口比较智障需要这样一个组合但是实际上好像测试的时候都没用到。。。
```cpp
std::string data_read = peek_output(len);
pop_output(len);
return data_read;
```
最智障的是它的`peek_output`和`pop_output`这两个的设计peek只能读啥也不能动因为是个const函数pop需要再把东西删掉然后`read`就是他们的组合。需要注意一下,更新`bytes_read`是在pop里面而不是read因为大概率在上层的实现中可能需要把直接调用peek和pop而不是read。