feat: Socket层SIGPIPE信号Crash

This commit is contained in:
liubinpeng
2021-04-06 11:38:32 +08:00
parent 9f6ba31efc
commit 0fa61f3513

View File

@@ -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.