本文整理汇总了C++中TcpSocket::Create方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::Create方法的具体用法?C++ TcpSocket::Create怎么用?C++ TcpSocket::Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::Create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadData
virtual int ReadData(int fd)
{
int err = 0;
int clientFd = -1;
std::string ip;
int port = 0;
do {
err = mListenSocket->Accept(clientFd, ip, port);
if (0 != err) {
break;
}
TcpSocket *clientSocket = new TcpSocket();
err = clientSocket->Create(clientFd);
if (0 != err) {
break;
}
debug_log("accpeter accept client " << ip << ":" << port);
clientSocket->SetAddr(ip, port);
AcceptContext *ctx = new AcceptContext(clientSocket);
mNetService->Enqueue(ctx);
OperContext::DecRef(ctx);
} while(0);
return 0;
}
示例2: Accept
Socket::Status TcpListener::Accept(TcpSocket& socket)
{
if (GetHandle() == be::SocketBE::invalidSocket())
{
return Error;
}
sockaddr_in address;
be::SocketBE::AddrLength length = sizeof(address);
SocketHandle remote = ::accept(GetHandle(), reinterpret_cast<sockaddr*>(&address), &length);
if (remote == be::SocketBE::invalidSocket())
return be::SocketBE::getErrorStatus();
socket.Close();
socket.Create(remote);
return Done;
}
示例3: Accept
Socket::Status TcpListener::Accept(TcpSocket& socket)
{
// Make sure that we're listening
if (GetHandle() == priv::SocketImpl::InvalidSocket())
{
Err() << "Failed to accept a new connection, the socket is not listening" << std::endl;
return Error;
}
// Accept a new connection
sockaddr_in address;
priv::SocketImpl::AddrLength length = sizeof(address);
SocketHandle remote = accept(GetHandle(), reinterpret_cast<sockaddr*>(&address), &length);
// Check for errors
if (remote == priv::SocketImpl::InvalidSocket())
return priv::SocketImpl::GetErrorStatus();
// Initialize the new connected socket
socket.Close();
socket.Create(remote);
return Done;
}