本文整理汇总了C++中TCPSocket::Socket方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPSocket::Socket方法的具体用法?C++ TCPSocket::Socket怎么用?C++ TCPSocket::Socket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPSocket
的用法示例。
在下文中一共展示了TCPSocket::Socket方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Handshake
void TLSSocket::Handshake(TCPSocket& socket, HandshakeRole role, TLSSocket* reuse)
{
SSL_CTX* ctx = role == Client ? TLSClientContext::Get() : TLSServerContext::Get();
if (!ctx) throw TLSError("TLS context not initialised.");
session = SSL_new(ctx);
if (!session) throw TLSProtocolError();
if (SSL_set_fd(session, socket.Socket()) != 1) throw TLSProtocolError();
if (reuse)
{
assert(reuse->session);
SSL_copy_session_id(session, reuse->session);
}
if (role == Client) SSL_set_connect_state(session);
else SSL_set_accept_state(session);
int result;
while (true)
{
if (role == Client) result = SSL_connect(session);
else result = SSL_accept(session);
boost::this_thread::interruption_point();
if (result == 1) break;
else EvaluateResult(result);
}
}
示例2: Handshake
void TLSSocket::Handshake(TCPSocket& socket, HandshakeRole role)
{
session = SSL_new(role == Client ?
TLSClientContext::Get() :
TLSServerContext::Get());
if (!session) throw TLSProtocolError();
if (SSL_set_fd(session, socket.Socket()) != 1) throw TLSProtocolError();
if (role == Client) SSL_set_connect_state(session);
else SSL_set_accept_state(session);
int result;
while (true)
{
if (role == Client) result = SSL_connect(session);
else result = SSL_accept(session);
boost::this_thread::interruption_point();
if (result == 1) break;
else EvaluateResult(result);
}
std::cout << SSL_version(session) << std::endl;
}