Пример #1
0
void TcpClient::removeConnection(const TcpConnectionPtr& conn)
{
    loop_->assertInLoopThread();
    assert(loop_ == conn->getLoop());
    assert(connection_ == conn);

    loop_->queueInLoop(std::bind(&TcpConnection::connectDestroyed, conn));
}
Пример #2
0
void TcpServer::removeConnectionInLoop(const TcpConnectionPtr& conn)
{
  _loop->assertInLoopThread();
  size_t n = _connections.erase(conn->name());
  (void)n;
  assert(n == 1);
  EventLoop* ioLoop = conn->getLoop();
  ioLoop->queueInLoop(
      std::bind(&TcpConnection::connectDestroyed, conn));
}
Пример #3
0
void TcpServer::removeConnectionInLoop(const TcpConnectionPtr& conn)
{
    m_loop->assertInLoopThread();
    LOG_INFO << "TcpServer::removeConnectionInLoop [" << m_name
        << "] - connection " << conn->name();
    size_t n = connections_.erase(conn->name());
    (void)n;
    assert(n == 1);
    EventLoop* ioLoop = conn->getLoop();
    ioLoop->queueInLoop(
        boost::bind(&TcpConnection::connectDestroyed, conn));
}
Пример #4
0
 void TcpServer::removeConnectionInLoop(const TcpConnectionPtr& conn)
 {
     loop_->assertInLoopThread();
     LOG_PRINT(LogType_Info, "TcpServer::removeConnectionInLoop [%s] - connection %s",
               name_.c_str(), conn->name().c_str());
     size_t n = connections_.erase(conn->name());
     (void)n;
     assert(n == 1);
     EventLoop* loop = conn->getLoop();
     loop->queueInLoop(
         std::bind(&TcpConnection::connectDestroyed, conn));
 }
Пример #5
0
TcpServer::~TcpServer()
{
  _loop->assertInLoopThread();

  for (ConnectionMap::iterator it(_connections.begin());
      it != _connections.end(); ++it)
  {
    TcpConnectionPtr conn = it->second;
    it->second.reset();
    conn->getLoop()->runInLoop(
      std::bind(&TcpConnection::connectDestroyed, conn));
    conn.reset();
  }
}
Пример #6
0
TcpServer::~TcpServer()
{
    m_loop->assertInLoopThread();
    LOG_TRACE << "TcpServer::~TcpServer [" << m_name << "] destructing";

    for (ConnectionMap::iterator it(connections_.begin());
        it != connections_.end(); ++it)
    {
        TcpConnectionPtr conn = it->second;
        it->second.reset();
        conn->getLoop()->runInLoop(
            boost::bind(&TcpConnection::connectDestroyed, conn));
        conn.reset();
    }
}
Пример #7
0
    TcpServer::~TcpServer()
    {
        loop_->assertInLoopThread();
        LOG_PRINT(LogType_Info, "TcpServer::~TcpServer [%s] destructing", name_.c_str());

        for(ConnectionMap::iterator it(connections_.begin());
                it != connections_.end(); ++it)
        {
            TcpConnectionPtr conn = it->second;
            it->second.reset();
            conn->getLoop()->runInLoop(
                std::bind(&TcpConnection::connectDestroyed, conn));
            conn.reset();
        }
    }
Пример #8
0
void TcpClient::removeConnection(const TcpConnectionPtr& conn){
    loop_->assertInLoopThread();
    assert(loop_ == conn->getLoop());

    {
        MutexLockGuard lock(mutex_);
        assert(connection_ == conn);
        connection_.reset();
    }

    loop_->queueInLoop(boost::bind(&TcpConnection::connectDestoryed, conn));
    if(retry_ && connect_){
        LOG_INFO << "TcpClient::connect[" << this << "] - reconnecting to "
                 << connector_->serverAddress().toHostPort();
        connector_->restart();
    }
}
Пример #9
0
 void onDisconnect(const TcpConnectionPtr& conn)
 {
     if(numConnected_.decrement() == 0)
     {
         printf("all disconnected\n");
         int64_t totalBytesRead = 0;
         int64_t totalMessagesRead = 0;
         for(std::vector<Session*>::iterator it = sessions_.begin(); it != sessions_.end(); ++it)
         {
             totalBytesRead += (*it)->bytesRead();
             totalMessagesRead += (*it)->messagesRead();
         }
         printf("%ld total bytes read\n", totalBytesRead);
         printf("%ld total messages read\n", totalMessagesRead);
         printf("%f average message size\n", static_cast<double>(totalBytesRead) / static_cast<double>(totalMessagesRead));
         printf("%f QPS\n", static_cast<double>(totalMessagesRead) / timeout_);
         printf("%f MiB/s throughput\n", static_cast<double>(totalBytesRead) / (timeout_ * 1024 * 1024));
         conn->getLoop()->queueInLoop(std::bind(&Client::quit, this));
     }
 }