Пример #1
0
void Sender::onConnection(const TcpConnectionPtr& conn)
{
	  LOG_INFO << "EchoServer - " << conn->peerAddress().toIpPort() << " -> "
           << conn->localAddress().toIpPort() << " is "
           << (conn->connected() ? "UP" : "DOWN");
	  
}
Пример #2
0
NAMESPACE_ZL_NET_START

void defaultConnectionCallback(const TcpConnectionPtr& conn)
{
  LOG_INFO("defaultConnectionCallback : [%s]<->[%s] [%s]\n", conn->localAddress().ipPort().c_str(),
        conn->peerAddress().ipPort().c_str(), conn->connected() ? "UP" : "DOWN");
}
Пример #3
0
 void onConnection(const TcpConnectionPtr& conn){
     LOG_INFO << conn->localAddress().toIpPort() << " -> "
              << conn->peerAddress().toIpPort() << " is "
              << (conn->connected() ? "UP" : "DOWN");
     if(!conn->connected())
         loop_->quit();
 }
Пример #4
0
	void OnConnection(const TcpConnectionPtr& conn)
	{
		LOG_INFO << conn->localAddress().toIpPort() << " -> "
             << conn->peerAddress().toIpPort() << " is "
             << (conn->connected() ? "UP" : "DOWN");
             	
    if(conn->connected())
    {
    	m_connection = conn;
    	if(g_aliveConnections.incrementAndGet() == g_connections)
    	{
    		LOG_INFO << "all connected";
    	}
    	else
    	{
    		m_connection.reset();
    		
    		if(g_aliveConnections.incrementAndGet() == g_connections)
    		{
    			LOG_INFO << "all disconnected";
    			g_loop->quit();
    		}
    	}
    }
	}
Пример #5
0
void P2PServer::onConnection(const TcpConnectionPtr& conn)
{
  cout << conn->localAddress().toIpPort() << " -> "
       << conn->peerAddress().toIpPort() << " is "
       << (conn->connected() ? "UP" : "DOWN") 
       << endl;

}
Пример #6
0
/***************************************************
Description:    处理新的json连接或者连接断开情况
Input:          conn:TCP连接
Output:         无
Return:         无
***************************************************/
void TCPServer::onJsonConnection(const TcpConnectionPtr &conn)
{
    LOG_DEBUG <<"JSONConnection: " << conn->peerAddress().toIpPort() << " -> "
             << conn->localAddress().toIpPort() << " is "
             << (conn->connected() ? "UP" : "DOWN");

    if(!conn->connected())
        jsonCodec_.cleanup(conn);
}
Пример #7
0
  void onConnection(const TcpConnectionPtr& conn)
  {
    LOG_TRACE << conn->peerAddress().toString() << " -> "
        << conn->localAddress().toString() << " is "
        << (conn->connected() ? "UP" : "DOWN");
    LOG_INFO << conn->getTcpInfoString();

   // conn->send("hello\n");
  }
Пример #8
0
/***************************************************
Description:    处理新的TCP连接或断开
Input:          无
Output:         无
Return:         无
***************************************************/
void TCPServer::onServerConnection(const TcpConnectionPtr& conn)
{
    conn->setTcpNoDelay(true);
    LOG_INFO << conn->peerAddress().toIpPort() << " -> "
             << conn->localAddress().toIpPort() << " is "
             << (conn->connected() ? "UP" : "DOWN");

    if(!conn->connected())
    {
        clearConnectionInfo(conn);
    }
}
Пример #9
0
void serverConnectionCallback(const TcpConnectionPtr& conn)
{
	LOG_TRACE << conn->name() << " " << conn->peerAddress().toIpPort() << " -> "
        		<< conn->localAddress().toIpPort() << " is "
        		<< (conn->connected() ? "UP" : "DOWN");
  if (conn->connected())
  {
    conn->setTcpNoDelay(true);
  }
  else
  {
  }
}
Пример #10
0
void onConnection(const TcpConnectionPtr& conn){
    LOG_INFO << "FileServer - " << conn->peerAddress().toIpPort() << " -> "
             << conn->localAddress().toIpPort() << " is " 
             << (conn->connected() ? "UP" : "DOWN");
    if(conn->connected()){
        LOG_INFO << "FileServer - Sending file " << g_file
                 << " to " << conn->peerAddress().toIpPort();
        conn->setHighWaterMarkCallback(onHighWaterMark, 64*1024);
        string fileContent = readFile(g_file);
        conn->send(fileContent);
        conn->shutdown();
        LOG_INFO << "FileServer - done";
    }
}
Пример #11
0
 void onConnection(const TcpConnectionPtr& conn)
 {
     cout << conn->peerAddress().ipPort() << " -> " << conn->localAddress().ipPort()
         << " is " << (conn->connected() ? "UP" : "DOWN") << "\n";
     clientConnection = conn;
     if (conn->connected())
     {
         //conn->setNoDelay(true);
     }
     else
     {
         //clientConnection.reset();
     }
 }
Пример #12
0
void clientConnectionCallback(const TcpConnectionPtr& conn)
{
	LOG_TRACE << conn->localAddress().toIpPort() << " -> "
        		<< conn->peerAddress().toIpPort() << " is "
        		<< (conn->connected() ? "UP" : "DOWN");
  if (conn->connected())
  {
    clientConnection = conn;
    conn->setTcpNoDelay(true);
  }
  else
  {
    clientConnection.reset();
  }
}
Пример #13
0
void EchoServer::onConnection(const TcpConnectionPtr& conn){
    LOG_INFO << "EchoServer - " << conn->peerAddress().toIpPort() << " -> "
             << conn->localAddress().toIpPort() << " is "
             << (conn->connected() ? "UP" : "DOWN");

    if(conn->connected()){
        ++numConnected_;
        if(numConnected_ > kMaxConnections_){
            conn->shutdown();
            conn->forceCloseWithDelay(3.0); // > round trip of the whole Internet.
        }
    }else{
        --numConnected_;
    }
    LOG_INFO << "numConnected = " << numConnected_;
}
Пример #14
0
void MyTcpClient::onConnection(const TcpConnectionPtr& conn)
{
    LOG_INFO << conn->localAddress().toIpPort() << " -> "
             << conn->peerAddress().toIpPort() << " is "
             << (conn->connected() ? "UP" : "DOWN");

    MutexLockGuard lock(mutex_);
    if (conn->connected())
    {
        connection_ = conn;
    }
    else
    {
        connection_.reset();
    }
}
Пример #15
0
	void onConnection(const TcpConnectionPtr& conn)
	{
		LOG_TRACE << conn->localAddress().toIpPort() << " -> "
			<< conn->peerAddress().toIpPort() << " is "
			<< (conn->connected() ? "UP" : "DOWN");

		if (conn->connected())
		{
			conn->setTcpNoDelay(true);
			conn->send(message_);
		}
		else
		{
			loop_->quit();
		}
	}
Пример #16
0
        //新连接或断开时的回调
        void onConnection(const TcpConnectionPtr &conn)
        {
            LOG_INFO <<conn->localAddress().toIpPort() << "->"
                     <<conn->peerAddress().toIpPort() << "is"
                     <<(conn->connected() ? "UP" : "DOWN");

            if(conn->connected())
            {
                //插入到用户集合中
                connections_.insert(conn);
            }
            else
            {
                //从集合中删除用户
                connections_.erase(conn);
            }
        }
Пример #17
0
void ProxyServer::onClientConnection(const TcpConnectionPtr& conn)
{
	LOG_TRACE << "Client " << conn->peerAddress().toIpPort() << " -> "
			<< conn->localAddress().toIpPort() << " is " 
			<< (conn->connected() ? "online" : "offline");
	
	std::string connname(conn->name().c_str());
	if(conn->connected())
	{
		m_conns[connname] = conn;
	//	m_redis.command(boost::bind(&ProxyServer::onRedisGetResult,this,_1,_2),"BRPOP test 0");
	}
	else
	{
		LOG_INFO << "connname offline " << connname;
		m_conns.erase(connname);
	}	
			
}
Пример #18
0
void ZGWServer::onClientConnection(const TcpConnectionPtr& conn)
{
    LOG_INFO << "Client " << conn->peerAddress().toIpPort() << " -> "
        << conn->localAddress().toIpPort() << " is "
        << (conn->connected() ? "UP" : "DOWN");

    if( conn->connected() )
    {
        int id = -1;
        if( !idQueue_.empty() )
        {
            id = idQueue_.front();
            idQueue_.pop();
            id2conn_[id] = conn;
        }

        if( -1 == id )
        {
            LOG_ERROR << "[过载保护]系统到达最大连接数,拒绝连接";
            conn->shutdown();
        }
        else
        {
            conn->setContext(id);
            LOG_INFO << "新连接[" << conn->peerAddress().toIpPort() << "]流水ID: " << id;
        }
    }
    else
    {
        if(!conn->getContext().empty())
        {
            int id = boost::any_cast<int>(conn->getContext());
            assert(id > 0 && id <= static_cast<int>(kMaxConns));

            // 回收连接的key
            idQueue_.push(id);
            id2conn_.erase(id);
        }
    }
}
Пример #19
0
/*
 * private functions
 *
 */
void tcp_server::onConnection(const TcpConnectionPtr& conn)
{
	LOG_DEBUG << "tcp_server - " << conn->peerAddress().toIpPort() << " -> " << conn->localAddress().toIpPort() << " is "
			<< (conn->connected() ? "UP" : "DOWN");
	
	if (conn->connected())
	{
		++numConnected_;
		if (numConnected_ > kMaxConnections_)
		{
			conn->shutdown();
		}
		else
		{
			conn->setTcpNoDelay(true);
		}
	}
	else
	{
		--numConnected_;
	}
	
	LOG_DEBUG << "numConnected = " << numConnected_;
}
Пример #20
0
 void OnConnection(const TcpConnectionPtr& conn)
 {
     LOG_TRACE << conn->peerAddress().toIpPort() << " -> "
               << conn->localAddress().toIpPort() << " is "
               << (conn->connected() ? "UP" : "DOWN");
 }
Пример #21
0
void BaseSvr::onAcceptConnection(const TcpConnectionPtr& conn)
{
    LOG_TRACE << "onAcceptConnection" << conn->peerAddress().IpAndPort() << " -> "
        << conn->localAddress().IpAndPort() << " is "
        << (conn->connected() ? "UP" : "DOWN");
}