示例#1
0
std::string Contacts::pushContact(int socketID, std::string nickName, std::string pass){
    if(getSocketID(nickName) == -2){
        pthread_mutex_lock(&_lock);
        Contact newContact (socketID, nickName, pass);
        _contacts.push_back(newContact);
        pthread_mutex_unlock(&_lock);
        return "success registation";
    }else{
        return "iam:failed";
    }
}
示例#2
0
bool ClientLogicSession::processRedisSingleCommand(parse_tree* parse, std::string* requestStr)
{
    bool isSuccess = false;

    int serverID;
    if (sharding_key(parse->tmp_buff, strlen(parse->tmp_buff), serverID))
    {
        isSuccess = true;
        BaseWaitReply::PTR w = std::make_shared<RedisSingleWaitReply>(this);
        auto server = findBackendByID(serverID);
        w->addWaitServer(server->getSocketID());
        server->pushPendingWaitReply(w);
        server->send(requestStr->c_str(), requestStr->size());

        mPendingReply.push_back(w);
    }

    return isSuccess;
}
示例#3
0
/*  收到网络层发送过来的db reply  */
void BackendLogicSession::onMsg(const char* buffer, int len)
{
    if (!mPendingWaitReply.empty())
    {
        ClientLogicSession* client = nullptr;
        auto w = mPendingWaitReply.front();
        auto wp = w.lock();
        if (wp != nullptr)
        {
            wp->onBackendReply(getSocketID(), buffer, len);
            client = wp->getClient();
        }
        mPendingWaitReply.pop();
        if (client != nullptr)
        {
            client->processCompletedReply();
        }
    }
}
示例#4
0
bool ClientLogicSession::procSSDBSingleCommand(SSDBProtocolResponse* request, std::string* requestStr)
{
    bool isSuccess = false;

    Bytes* b = request->getByIndex(1);
    int serverID;
    if (sharding_key(b->buffer, b->len, serverID))
    {
        isSuccess = true;
        BaseWaitReply::PTR w = std::make_shared<SSDBSingleWaitReply>(this);
        auto server = findBackendByID(serverID);
        w->addWaitServer(server->getSocketID());
        server->pushPendingWaitReply(w);
        server->send(requestStr->c_str(), requestStr->size());

        mPendingReply.push_back(w);
    }

    return isSuccess;
}