Esempio n. 1
0
bool PosixSelectorBase::Poll(double timeout)
{
#ifdef POSIX_OK_NETADDR
	TryConnecting();
#endif // POSIX_OK_NETADDR

	return PollInternal(timeout);
}
Esempio n. 2
0
redisReply * RedisClient::RedoCommand(const std::string & command, int32_t expect_type){
    if(nullptr == m_redis_conn){
        TryConnecting();
    }
    if( command.empty())
        return nullptr;

    redisReply *redis_reply = nullptr;
    do{
        {
            std::lock_guard<std::mutex> l(m_conn_mutex); // For test
            redis_reply = static_cast<redisReply*>(redisCommand(m_redis_conn, command.c_str() ));
        }
        if( nullptr == redis_reply ){
            if(TryConnecting())
                continue;
            else {
                LOGE("RedoCommand -- can't connect . command : "<<command<<" failed!");
                break;
            }
        }
        if( expect_type == REDIS_REPLY_ERROR ){
            break;
        }
        if( REDIS_REPLY_ERROR == redis_reply->type ) {
            LOGE("RedoCommand -- redis error msg="<< redis_reply->str\
                  << ", cmd=" << command);
        }else if ( REDIS_REPLY_NIL == redis_reply->type ) {
            LOGW("RedoCommand -- REDIS_REPLY_NIL! command=" << command);
        }else if ( expect_type == redis_reply->type ){
            if(expect_type != REDIS_REPLY_STATUS )
                break;
            if( redis_reply->str == std::string("OK") )
                break;
            LOGE("RedoCommand -- get status not OK ! command=" << command\
                  <<" got status  "<< redis_reply->str);
        }else{
            LOGE("RedoCommand -- get type wrong ! command=" << command \
                 <<" type "<< redis_reply->type );
        }
        freeReplyObject_Safe(redis_reply);
        break;
    }while(1);
    return redis_reply;
}
Esempio n. 3
0
void RedisClient::Init(const std::string& ip, const std::string& port){
    if( ip.empty() || port.empty()) {
        LOGE("RedisClient Error : empty param !");
    }
    m_ip = ip;
    m_port = std::atoi(port.c_str());
    LOGD("RedisClient try to connect redis: " << m_ip << " : " <<  m_port);
    TryConnecting();
}
Esempio n. 4
0
void PosixSelectorBase::TryConnecting()
{
	for (Watched *toconnect = m_connecting.First(), *next; toconnect; toconnect = next)
	{
		next = toconnect->Suc();
		TryConnecting(toconnect);

		// "next" element can be detached during
		// the "TryConnecting(toconnect)" call.
		// If it happened - restart the loop.
		if (next && !m_connecting.HasLink(next))
			next = m_connecting.First();
	}
}