Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion network/2_http/http_websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ HTTP 状态码=200(正常响应)的情况,大家见得多了。101 确实
- 等于 2,是二进制数据类型(`[]byte`)的数据包
- 等于 8,是关闭连接的信号

**payload 字段**:存放的是我们**真正想要传输的数据的长度**,单位是**字节**。比如你要发送的数据是 `字符串"111"`,那它的长度就是 `3`。
**Payload Length 字段**:存放的是我们**真正想要传输的数据的长度**,单位是**字节**。比如你要发送的数据是 `字符串"111"`,那它的长度就是 `3`。

![图片](https://img-blog.csdnimg.cn/img_convert/437a076935f82be1d36960c9a4785fbd.png)

Expand Down
2 changes: 1 addition & 1 deletion network/3_tcp/isn_deff.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Linux 以本地时钟计数(jiffies)作为时间戳的值,不同的增长
- 如果时钟计数提高到 1 us 加 1,则回绕需要约 71.58 分钟才能回绕,这时问题也不大,因为网络中旧报文几乎不可能生存超过 70 分钟,只是如果 70 分钟没有报文收发则会有一个包越过 PAWS(这种情况会比较多见,相比之下 24 天没有数据传输的 TCP 连接少之又少),但除非这个包碰巧是序列号回绕的旧数据包而被放入接收队列(太巧了吧),否则也不会有问题;
- 如果时钟计数提高到 0.1 us 加 1 回绕需要 7 分钟多一点,这时就可能会有问题了,连接如果 7 分钟没有数据收发就会有一个报文越过 PAWS,对于 TCP 连接而言这么短的时间内没有数据交互太常见了吧!这样的话会频繁有包越过 PAWS 检查,从而使得旧包混入数据中的概率大大增加;

Linux 在 PAWS 检查做了一个特殊处理,如果一个 TCP 连接连续 24 天不收发数据则在接收第一个包时基于时间戳的 PAWS 会失效,也就是可以 PAWS 函数会放过这个特殊的情况,认为是合法的,可以接收该数据包。
Linux 在 PAWS 检查做了一个特殊处理,如果一个 TCP 连接连续 24 天不收发数据则在接收第一个包时基于时间戳的 PAWS 会失效,也就是 PAWS 函数会放过这个特殊的情况,认为是合法的,可以接收该数据包。

```c
// tcp_paws_check 函数如果返回 true 则 PAWS 通过:
Expand Down
2 changes: 1 addition & 1 deletion network/3_tcp/port.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 4.18 TCP 和 UDP 可以使用同一个端口吗?
# 4.19 TCP 和 UDP 可以使用同一个端口吗?

大家好,我是小林。

Expand Down
2 changes: 1 addition & 1 deletion network/3_tcp/quic.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 4.17 如何基于 UDP 协议实现可靠传输?
# 4.18 如何基于 UDP 协议实现可靠传输?

大家好,我是小林。

Expand Down
2 changes: 1 addition & 1 deletion network/3_tcp/tcp_drop.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 4.21 用了 TCP 协议,数据一定不会丢吗?
# 4.22 用了 TCP 协议,数据一定不会丢吗?

> 来源:公众号@小白 debug
>
Expand Down
2 changes: 1 addition & 1 deletion network/3_tcp/tcp_http_keepalive.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 4.15 TCP Keepalive 和 HTTP Keep-Alive 是一个东西吗?
# 4.16 TCP Keepalive 和 HTTP Keep-Alive 是一个东西吗?

大家好,我是小林。

Expand Down
2 changes: 1 addition & 1 deletion network/3_tcp/tcp_no_accpet.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 4.20 没有 accept,能建立 TCP 连接吗?
# 4.21 没有 accept,能建立 TCP 连接吗?

> 来源:公众号@小白 debug
> 原文地址:[阿里二面:没有 accept,能建立 TCP 连接吗?](https://mp.weixin.qq.com/s/oPX_JoZUaLn6sW54yppfvA)
Expand Down
2 changes: 1 addition & 1 deletion network/3_tcp/tcp_no_listen.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 4.19 服务端没有 listen,客户端发起连接建立,会发生什么?
# 4.20 服务端没有 listen,客户端发起连接建立,会发生什么?

大家好,我是小林。

Expand Down
2 changes: 1 addition & 1 deletion network/3_tcp/tcp_problem.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 4.16 TCP 协议有什么缺陷?
# 4.17 TCP 协议有什么缺陷?

大家好,我是小林。

Expand Down
2 changes: 1 addition & 1 deletion network/3_tcp/tcp_three_fin.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 4.22 TCP 四次挥手,可以变成三次吗?
# 4.23 TCP 四次挥手,可以变成三次吗?

大家好,我是小林。

Expand Down
2 changes: 1 addition & 1 deletion network/3_tcp/tcp_tls.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 4.14 HTTPS 中 TLS 和 TCP 能同时握手吗?
# 4.15 HTTPS 中 TLS 和 TCP 能同时握手吗?

大家好,我是小林。

Expand Down
2 changes: 1 addition & 1 deletion os/5_schedule/schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ FCFS 对长作业有利,适用于 CPU 繁忙型作业的系统,而不适用
- 最佳页面置换算法(*OPT*)
- 先进先出置换算法(*FIFO*)
- 最近最久未使用的置换算法(*LRU*)
- 时钟页面置换算法(*Lock*)
- 时钟页面置换算法(*Clock*)
- 最不常用置换算法(*LFU*)

### 最佳页面置换算法
Expand Down
2 changes: 1 addition & 1 deletion os/6_file_system/pagecache.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

因为进程在执行 write(使用缓冲 IO)系统调用的时候,实际上是将文件数据写到了内核的 page cache,它是文件系统中用于缓存文件数据的缓冲,所以即使进程崩溃了,文件数据还是保留在内核的 page cache,我们读数据的时候,也是从内核的 page cache 读取,因此还是依然读的进程崩溃前写入的数据。

内核会找个合适的时机,将 page cache 中的数据持久化到磁盘。但是如果 page cache 里的文件数据,在持久化到磁盘化到磁盘之前,系统发生了崩溃,那这部分数据就会丢失了。
内核会找个合适的时机,将 page cache 中的数据持久化到磁盘。但是如果 page cache 里的文件数据,在持久化到磁盘之前,系统发生了崩溃,那这部分数据就会丢失了。

当然,我们也可以在程序里调用 fsync 函数,在写文文件的时候,立刻将文件数据持久化到磁盘,这样就可以解决系统崩溃导致的文件数据丢失的问题。

Expand Down