本文整理汇总了C++中TcpConnectionPtr::disconnect方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpConnectionPtr::disconnect方法的具体用法?C++ TcpConnectionPtr::disconnect怎么用?C++ TcpConnectionPtr::disconnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpConnectionPtr
的用法示例。
在下文中一共展示了TcpConnectionPtr::disconnect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onTcpRecvComplete
//-----------------------------------------------------------------------------
// 描述: TCP连接上的一个接收任务已完成
//-----------------------------------------------------------------------------
void AppBusiness::onTcpRecvComplete(const TcpConnectionPtr& connection, void *packetBuffer,
int packetSize, const Context& context)
{
logger().writeStr("onTcpRecvComplete");
string msg((char*)packetBuffer, packetSize);
msg = trimString(msg);
if (msg == "quit")
connection->disconnect();
else
connection->send((char*)packetBuffer, packetSize);
logger().writeFmt("Received message: %s", msg.c_str());
}
示例2: onTcpConnected
void AppBusiness::onTcpConnected(const TcpConnectionPtr& connection)
{
const int MAX_CONN_COUNT = 3;
logger().writeFmt("onTcpConnected (%s) (ConnCount: %d)",
connection->getPeerAddr().getDisplayStr().c_str(),
connection->getServerConnCount());
int connCount = connection->getServerConnCount();
if (connCount > MAX_CONN_COUNT)
{
logger().writeFmt("Too many connections. (ConnCount: %d)", connCount);
connection->disconnect();
}
else
{
string msg = "Welcome to the simple echo server, type 'quit' to exit.\r\n";
connection->send(msg.c_str(), msg.length());
}
}
示例3: onTcpSendComplete
void ServerModule_Daytime::onTcpSendComplete(const TcpConnectionPtr& connection, const Context& context)
{
logger().writeStr("onTcpSendComplete");
connection->disconnect();
}