mirror of
https://github.com/NohamR/knowledge-kit.git
synced 2026-05-25 12:27:15 +00:00
feat: Socket层SIGPIPE信号Crash
This commit is contained in:
@@ -40,6 +40,15 @@ Mach 异常都在 host 层被 `ux_exception` 转换为相应的 unix 信号,
|
|||||||
setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof(value));
|
setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof(value));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
`SO_NOSIGPIPE` 是一个宏定义,跳过去看一下实现
|
||||||
|
|
||||||
|
```c++
|
||||||
|
#define SO_NOSIGPIPE 0x1022 /* APPLE: No SIGPIPE on EPIPE */
|
||||||
|
```
|
||||||
|
|
||||||
|
什么意思呢?没有 SIGPIPE 信号在 EPIPE。那啥是 `EPIPE`。
|
||||||
|
|
||||||
其中:**EPIPE** 是 socket send 函数可能返回的错误码之一。如果发送数据的话会在 Client 端触发 RST(指Client端的 FIN_WAIT_2 状态超时后连接已经销毁的情况),导致send操作返回 `EPIPE`(errno 32)错误,并触发 `SIGPIPE` 信号(默认行为是 **Terminate**)。
|
其中:**EPIPE** 是 socket send 函数可能返回的错误码之一。如果发送数据的话会在 Client 端触发 RST(指Client端的 FIN_WAIT_2 状态超时后连接已经销毁的情况),导致send操作返回 `EPIPE`(errno 32)错误,并触发 `SIGPIPE` 信号(默认行为是 **Terminate**)。
|
||||||
|
|
||||||
> What happens if the client ignores the error return from readline and writes more data to the server? This can happen, for example, if the client needs to perform two writes to the server before reading anything back, with the first write eliciting the RST.
|
> What happens if the client ignores the error return from readline and writes more data to the server? This can happen, for example, if the client needs to perform two writes to the server before reading anything back, with the first write eliciting the RST.
|
||||||
|
|||||||
Reference in New Issue
Block a user