110 lines
3.0 KiB
Markdown
110 lines
3.0 KiB
Markdown
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。 |