Boost asio network disconnection handling

柔情痞子 提交于 2021-01-28 12:42:20

问题


I am using boost asio for my TCP Server, in this I am using async_read_some for reading . Application is working fine when network is connected, normal connection closing are handled correctly like (EOF,abrupt closing). But my problem is I am not getting any error when network cable is unplugged. socket is open , and I get error when I am writing on socket. This is the way socket work. Question: Can this is handled in Boost asio by any method?


回答1:


You may want to set "keep alive" on the socket, see Socket closed notification. Try:

socket.set_option(boost::asio::socket_base::keep_alive(true));


来源:https://stackoverflow.com/questions/22652293/boost-asio-network-disconnection-handling

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!