select 未检测到本地主机连接已关闭
我用 C winapi 设计了一个小型 Web 服务器。
我使用 select 来检测来自本地主机 (Firefox) 的“连接已关闭”。
我在本地服务器上使用 Firefox 发起请求,我的软件会等待,直到我关闭与 Firefox 的连接(停止按钮)。
如果我在大约十秒后关闭 Firefox 的连接,我的软件就能够检测到连接已关闭。
但是,如果我在一分钟后关闭连接,我的软件不会检测到任何内容...
只有当我关闭 Firefox 时,最终会检测到关闭的连接或者...最终被 Firefox 关闭?!
I design a little web server in C winapi.
I use select to detect a 'connection closed' from the localhost (Firefox).
I launch a request with Firefox on my local server, and my software wait until I close the connection with Firefox (stop button).
If I close the connection from Firefox after about ten seconds, my software is able to detect the connection closed.
But, if I close the connection after one minute, my software doesn't detect anything...
ONLY, when I close Firefox, the connection closed is finally detected or ... finally closed by firefox ?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
套接字关闭的检测可能很大程度上取决于套接字关闭的方式/原因以及连接的其他特征。我发现在合理的时间内检测关闭连接的一种方法是尝试写入连接(如在两个方向上建立定期轮询)。这应该会立即导致错误。
我不确定这对您的特定情况有什么帮助。
Detection of the closing of a socket can be very dependent on how/why the socket was closed along with other characteristics of the connection. I've found that one way to detect a closed connection in a reasonable amount of time is to attempt to write to the connection (as in establishing a periodic poll in both directions). That should result in an immediate error.
How this helps in your particular case, I'm not sure.