C++ Functions According to TCP

2019-02-21 03:19发布

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条回答
Anthone
2楼-- · 2019-02-21 03:35

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 :

查看更多
登录 后发表回答