C++ Functions According to TCP

半城伤御伤魂 提交于 2019-12-01 12:14:46

问题


I'm using recv function (C++) in order to get indication about network problem (it return negative value in this case)

Looking here: http://tools.ietf.org/html/rfc1122#page-100 at TCP Connection Failures, I see that there are R1 and R2.

R1 is when TCP informs application that there is a problem. R2 is when the connection is closed.

“The value of R1 SHOULD correspond to at least 3 retransmissions, at the current RTO. The value of R2 SHOULD correspond to at least 100 seconds.”

RTO (Retransmission Timeout) typically starts at 3 seconds, so for R1, it might be after about 10 seconds.

as far as I understand receive function will let me know about R2. Do you know about a way to get R1 in C++ application?

10x.


回答1:


On most systems, recv() transmit informations by two means : the return code and by setting the global variable errno.

To know what is returned/set in each case, you have to look at the exact API of the recv() function.

  • R1 (problem) : recv() returns SOCKET_ERROR (windows) or -1 (linux), then you look at the value from WSAGetLastError (windows) or errno (linux) for details
  • R2 (connexion closed) : I'm not sure, the API is unclear. Just try it out ;-)

Full doc :

  • windows : http://msdn.microsoft.com/en-us/library/windows/desktop/ms740121%28v=vs.85%29.aspx
  • linux : http://www.linux-kheops.com/doc/man/manfr/man-html-0.9/man2/recv.2.html


来源:https://stackoverflow.com/questions/8244332/c-functions-according-to-tcp

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