如何处理客户端断开连接(epoll) [英] How do I handle client disconnect (epoll)

查看:339
本文介绍了如何处理客户端断开连接(epoll)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用epoll进行网络编程。我想知道我如何可以处理客户端断开连接。我读取api文档和epoll_wait有一个超时的参数。但是,如果epoll_wait函数或正在连接的客户端超时,我很困惑。

I am working on a network programming using epoll. I was wondering how I can handle client disconnect. I read api document and epoll_wait had a argument for timeout. However, I was confused if the time out for the epoll_wait function or for the client that are being connected.

提前感谢。

推荐答案

timeout指定的是epoll_wait 。要处理客户端断开连接,处理由epoll引发的EPOLLHUP,并检查套接字上的recv函数是否返回零,表示套接字断开连接。

timeout specified is for epoll_wait. To handle client disconnect, Handle EPOLLHUP raised by epoll and also check if the recv function on socket returns zero that means socket is disconnected.

这篇关于如何处理客户端断开连接(epoll)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆