C++ simple way to set timeout

  • 2020-04-02 02:56:41
  • OfStack

The example of this article describes the C++ set timeout time simple implementation method, code is simple to understand, functional practical. Share with you for your reference. The specific implementation method is as follows:

BOOL SetTimeOut(SOCKET s, int nTime, BOOL bRecv)  

    int ret = ::setsockopt(s, SOL_SOCKET, bRecv?SO_RCVTIMEO:SO_SNDTIMEO, (char*)nTime, sizeof(nTime)); 
    return ret!=SOCKET_ERROR; 
}

Here setsockopt is for the operation of the sleeve interface, interested friends can consult the relevant information for further understanding.

Hope that the article described in the C++ programming to help you.


Related articles: