問題描述
基于此問題,當(dāng)您調(diào)用 closesocket()
在 recv()
已經(jīng)使用的套接字上,然后 RST
數(shù)據(jù)包將被發(fā)送到另一端,而不是執(zhí)行正常的斷開連接 (4-方式握手).
Based on this question, when you call closesocket()
on a socket that recv()
is already using, then an RST
packet will be sent to the other side instead of performing a graceful disconnection (4-way handshake).
但我希望執(zhí)行一個(gè)優(yōu)雅的斷開連接,所以我需要在調(diào)用 closesocket()
之前退出 recv()
.
But I wish to perform a graceful disconnection, so I need to exit recv()
before calling closesocket()
.
有沒有辦法做到這一點(diǎn)?
Is there a way to do that?
推薦答案
您可以shutdown()
用于輸入的套接字.recv()
將解除阻塞并返回零,每個(gè)人都會(huì)很高興.
You can shutdown()
the socket for input. The recv()
will unblock and return zero and everybody will be happy.
這篇關(guān)于如何退出阻塞的 recv() 調(diào)用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!