Beispiel #1
0
bool ClientPool::bind(Ice::Long connection, const JidPtr& j,
		const string& ticket, bool flush) {
	MCE_DEBUG("ClientPool::bind --> connectionId:" << connection << " jid:" << jidToString(j));
	int isBind = 0;
	Ice::Long oldConId = 0;
	bool res = true;
	{
		IceUtil::Mutex::Lock lock(_mutex);
		map<Ice::Long,ClientBufferPtr>::iterator it = _clients.find(j->index);
		if (it == _clients.end()) {
			ClientBufferPtr c = new ClientBuffer();
			c->bind(j,connection);
			_clients[j->index] = c;
			c->timestamp(time(NULL));
			isBind = 1;
		} else {
			//if(flush && it->second->isFlush()) {
			//	isBind = 2;
			//}
			oldConId = it->second->activeConnection();
			bool res = it->second->bind(j,connection);
			if(res == false) {
				return false;
			}
			it->second->timestamp(time(NULL));

			if(oldConId != connection && oldConId) {
				IdleConnManager::instance().cometConnSwitch();
			}else{
				oldConId = 0;
			}
		}
	}

	if(isBind > 0){
		try {
			MCE_INFO("ClientPool::bind --> invoke WTalkProxy bind " << isBind << ", " << jidToString(j) << ", ac_conn " << connection);
			res = WTalkProxyAdapter::instance().bind(boost::lexical_cast<string>(j->index), ticket, j);
		} catch(Ice::Exception& e) {
			MCE_WARN("ClientPool::bind --> invoke WTalkProxy bind err" << isBind << ", " << jidToString(j) << ", ac_conn " << connection << ", " << e);
		}
	}
	if(oldConId > 0){
		SessionPtr s = Server::instance().getSession(oldConId);
		SessionPtr newSession = Server::instance().getSession(connection);
		if (s) {
			s->needUnbind(false);
			MCE_DEBUG("ClientPool::bind --> jid " << jidToString(j)
				<< " change from " << s->jid()->userId << "_" << oldConId
				<< " to " << newSession->jid()->userId << "_" << connection);
			s->responseClose(211,"code:211, comet old connection close");
		}
	}
	return res;
}