gpt4 book ai didi

c - 如何在 Linux 上的 C 中检测套接字上的 CLOSE_WAIT?

转载 作者:太空狗 更新时间:2023-10-29 12:31:05 24 4
gpt4 key购买 nike

我正在编写 TCP 客户端,我想在连接中断时立即重新连接(即服务器重新启动)。我想尽快重新启动连接,即使没有数据要通过此套接字发送。我在 netstat 中看到连接处于 CLOSE_WAIT 状态,但是 select、getsockopt 或 getpeername 没有错误。我知道我可以尝试向套接字写入一些内容,但此连接仅用于读取。

最佳答案

来自 man recv :

Return Value

These calls return the number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutdown.

关于c - 如何在 Linux 上的 C 中检测套接字上的 CLOSE_WAIT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26999705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com