本文整理汇总了C++中TcpSocket::IsOpen方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::IsOpen方法的具体用法?C++ TcpSocket::IsOpen怎么用?C++ TcpSocket::IsOpen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::IsOpen方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Accept
bool Accept(TcpSocket& connection, bool blocking = true) const
{
if (!IsListening())
{
throw std::runtime_error("TcpSocket.Accept - Called on a socket that does not have listening mode enabled");
}
auto newSocket = SOCKET(0);
auto address = sockaddr_in();
auto tryAgain = bool();
do
{
tryAgain = false;
if (!Winsock::Accept(socket, address, newSocket))
{
switch (WSAGetLastError())
{
case WSAEWOULDBLOCK:
//if (!IsBlocking())
//{
// throw std::runtime_error("TcpSocket.Accept - Received would-block error for non-blocking socket");
//}
return false;
case WSAECONNRESET:
tryAgain = true;
break;
default:
return false;
}
}
} while (tryAgain);
if (connection.IsOpen())
{
connection.Close();
}
connection.socket = newSocket;
connection.isListening = false;
if (!Winsock::IoctlSocket(connection.socket, blocking))
{
throw std::runtime_error("TcpSocket.Accept - Unable to set blocking mode on new connection");
}
connection.isBlocking = blocking;
return true;
}