Пример #1
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();
    		}
    	}
    }
	}
Пример #2
0
 void onConnection(const TcpConnectionPtr& conn){
     LOG_INFO << conn->localAddress().toIpPort() << " -> "
              << conn->peerAddress().toIpPort() << " is "
              << (conn->connected() ? "UP" : "DOWN");
     if(!conn->connected())
         loop_->quit();
 }
Пример #3
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);
}
Пример #4
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);
    }
}
Пример #5
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
  {
  }
}
Пример #6
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";
    }
}
Пример #7
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();
     }
 }
Пример #8
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();
  }
}
Пример #9
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_;
}
Пример #10
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();
    }
}
Пример #11
0
void Sender::onConnection(const TcpConnectionPtr& conn)
{
	  LOG_INFO << "EchoServer - " << conn->peerAddress().toIpPort() << " -> "
           << conn->localAddress().toIpPort() << " is "
           << (conn->connected() ? "UP" : "DOWN");
	  
}
Пример #12
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");
}
Пример #13
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();
		}
	}
Пример #14
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);
            }
        }
Пример #15
0
void HttpServer::onConnection(const TcpConnectionPtr& conn)
{
     LOG_INFO("HttpServer::onConnection get one client %d", conn->fd());
     if (conn->connected())
     {
         conn->setContext(HttpContext());
     }
}
Пример #16
0
void P2PServer::onConnection(const TcpConnectionPtr& conn)
{
  cout << conn->localAddress().toIpPort() << " -> "
       << conn->peerAddress().toIpPort() << " is "
       << (conn->connected() ? "UP" : "DOWN") 
       << endl;

}
Пример #17
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");
  }
Пример #18
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);
	}	
			
}
Пример #19
0
void NodeServer::onConnection(const TcpConnectionPtr& conn) {
	muduo::Timestamp time = muduo::Timestamp::now();
	if (conn->connected()) {
		//this is connected!
		msgController_.onConnection(conn, time);
	} else {
		//this is disconnected!
		msgController_.onDisConnection(conn, time);
	}
}
Пример #20
0
	void onConnection(const TcpConnectionPtr& conn)
	{
		if (conn->connected())
		{
			//channel_.reset(new RpcChannel(conn));
			conn->setTcpNoDelay(true);
			channel_->setConnection(conn);
			allConnected_->countDown();
		}
	}
Пример #21
0
void onServerConnection(const TcpConnectionPtr& conn)
{
	LOG_DEBUG << conn->name() << (conn->connected() ? " UP" : " DOWN");

	if (conn->connected())
	{
		conn->setTcpNoDelay(true);

		TunnelPtr tunnel(new Tunnel(g_eventLoop, g_serverAddr, conn));

		tunnel->setup();
		tunnel->connect();
		g_tunnels[conn->name()] = tunnel;

	}
	else
	{
		std::map<string, TunnelPtr>::iterator it = g_tunnels.find(conn->name());
	}
}
Пример #22
0
 //建立连接或断开时的回调
 void onConnection(const TcpConnectionPtr &conn)
 {
     MutexLockGuard lock(mutex_);
     if(conn->connected())
     {
         connection_ = conn;
     }
     else
     {
         connection_.reset();
     }
 }
Пример #23
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);
        }
    }
}
Пример #24
0
void Session::onConnection(const TcpConnectionPtr& conn)
{
    if(conn->connected())
    {
        conn->setNoDelay(true);
        conn->send(owner_->message());
        owner_->onConnect();
    }
    else
    {
        owner_->onDisconnect(conn);
    }
}
Пример #25
0
/***************************************************
Description:    向数据库代理模块(MySQLProxy或者HBaseProxy)发送信息 利用protobuf向数据库发消息
Calls:          MessageHandler::
Input:          messageToSend:待发送的protobuf message
                type:连接类型
Output:         无
Return:         无
***************************************************/
void TCPServer::sendProtoMessage(ProtoMessage messageToSend, ConnectionType type)
{
    TcpConnectionPtr dbProxyConn = LocalConnections::instance()[type];
    if(dbProxyConn->connected())
    {
        protoCodec_.send(dbProxyConn, messageToSend);
    }
    else
    {
        //保存发送失败的消息
        LOG_INFO << "Save unsend MySQL messages to UnSendMessages";
        UnSendMessages::instance()[type].push_back(messageToSend);
    }
}
Пример #26
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_;
}
Пример #27
0
void PubSubClient::onConnection(const TcpConnectionPtr& conn)
{
	if (conn->connected())
	{
		conn_ = conn;
		// FIXME: re-sub
	}
	else
	{
		conn_.reset();
	}
	if (connectionCallback_)
	{
		connectionCallback_(this); //
	}
}
Пример #28
0
void onConnection(const TcpConnectionPtr& conn)
{
	if (conn->connected())
	{
		printf("onConnection(): tid=%d new connection [%s] from %s\n",
			CurrentThread::tid(),
			conn->name().c_str(),
			conn->peerAddress().toIpPort().c_str());


		conn->send(message); //一连接就发送
	}
	else
	{
		printf("onConnection(): tid=%d connection [%s] is down\n",
			CurrentThread::tid(),
			conn->name().c_str());
	}
}
Пример #29
0
 void onConnection(const TcpConnectionPtr& conn) {
     if (conn->connected()) {
         connectionCount_.increment();
         conn->setContext(ConnectionContext());
         ConnectionContext* connectionContext
             = boost::any_cast<ConnectionContext>(conn->getMutableContext());
         EntryPtr entry(new Entry(conn));
         localConnectionBuckets_.get()->back().insert(entry);
         WeakEntryPtr weakEntry(entry);
         connectionContext->weakEntry_ = weakEntry;
     } else {
         connectionCount_.decrement();
         const ConnectionContext& connectionContext
             = boost::any_cast<const ConnectionContext&>(conn->getContext());
         const ConnectionSubscription& connSub = connectionContext.subscription_;
         // subtle: doUnsubscribe will erase *it, so increase before calling.
         for (auto it = connSub.begin(); it != connSub.end();) {
             doUnsubscribe(conn, *it++);
         }
     }
 }
Пример #30
0
	void onConnection(const TcpConnectionPtr& conn)
	{
		//不管客户端连上来的是sub还是pub,都首先创建一个ConnectionSubscription,虽然对sub来说,没有必要
		if (conn->connected())
		{
			conn->setContext(ConnectionSubscription()); //保存一个clinet订阅的主题


		}
		else
		{
			//连接断开,把这个client订阅的topic里面都取消
			const ConnectionSubscription& connSub
				= boost::any_cast<const ConnectionSubscription&>(conn->getContext());
			// subtle: doUnsubscribe will erase *it, so increase before calling.
			for (ConnectionSubscription::const_iterator it = connSub.begin();
				it != connSub.end();)
			{
				doUnsubscribe(conn, *it++);
			}

		}
	}