MCResult 
MemCacheClient::IncDec(
    const char *    a_pszType, 
    const char *    a_pszKey, 
    uint64_t *      a_pnNewValue,
    uint64_t        a_nDiff,
    bool            a_bWantReply
    )
{
    Server * pServer = FindServer(a_pszKey);
    if (!pServer) return MCERR_NOSERVER;

    char szBuf[50];
    string_t sRequest(a_pszType);
    sRequest += ' ';
    sRequest += a_pszKey;
    snprintf(szBuf, sizeof(szBuf), " " SPRINTF_UINT64, a_nDiff);
    sRequest += szBuf;
    if (!a_bWantReply) {
        sRequest += " noreply";
    }
    sRequest += "\r\n";

    try {
        pServer->SendBytes(sRequest.data(), sRequest.length());

        if (!a_bWantReply) {
            return MCERR_NOREPLY;
        }

        string_t sValue;
        sValue = pServer->GetByte();
        while (sValue[sValue.length()-1] != '\n') {
            sValue += pServer->GetByte();
        }

        if (sValue == "NOT_FOUND\r\n") {
            return MCERR_NOTFOUND;
        }

        if (a_pnNewValue) {
            *a_pnNewValue = STRTOUL64(sValue.data(), NULL, 10);
        }
        return MCERR_OK;
    }
    catch (const ServerSocket::Exception &) {
        pServer->Disconnect();
        return MCERR_NOSERVER;
    }
}
s64t TCalcDisplay::getDisplay() { 
   return hexmode ? STRTOUL64(number,0,16) : ATOI64(number);
}
int 
MemCacheClient::HandleGetResponse(
    Server *        a_pServer, 
    MemRequest **   a_ppBegin, 
    MemRequest **   a_ppEnd
    )
{
    int nFound = 0;

    string_t sValue;
    for (;;) {
        // get the value
        ReceiveLine(a_pServer, sValue);
        if (sValue == "END\r\n") break;

        // if it isn't a value then we are in a bad state
        if (0 != strncmp(sValue.data(), "VALUE ", 6)) {
            throw ServerSocket::Exception("bad response");
        }

        // extract the key
        int n = (int) sValue.find(' ', 6);
        if (n < 1) throw ServerSocket::Exception("bad response");
        string_t sKey(sValue, 6, n - 6);

        // extract the flags
        char * pVal = const_cast<char*>(sValue.data() + n + 1);
        unsigned nFlags = (unsigned) strtoul(pVal, &pVal, 10);
        if (*pVal++ != ' ') throw ServerSocket::Exception("bad response");

        // extract the size
        unsigned nBytes = (unsigned) strtoul(pVal, &pVal, 10);
        if (*pVal != ' ' && *pVal != '\r') throw ServerSocket::Exception("bad response");

        // find this key in the array
        MemRequest * pItem = NULL; 
        for (MemRequest ** p = a_ppBegin; p < a_ppEnd; ++p) {
            if ((*p)->mKey == sKey) { pItem = *p; break; }
        }
        if (!pItem) { // key not found, discard the response
            a_pServer->DiscardBytes(nBytes + 2); // +2 == include final "\r\n"
            continue;
        }
        pItem->mFlags = nFlags;

        // extract the cas
        if (*pVal == ' ') {
            pItem->mCas = STRTOUL64(++pVal, &pVal, 10);
            if (*pVal != '\r') throw ServerSocket::Exception("bad response");
        }

        // receive the data
        while (nBytes > 0) {
            char * pBuf = pItem->mData.GetWriteBuffer(nBytes);
            int nReceived = a_pServer->GetBytes(pBuf, nBytes);
            pItem->mData.CommitWriteBytes(nReceived);
            nBytes -= nReceived;
        }
        pItem->mResult = MCERR_OK;

        // discard the trailing "\r\n"
        if ('\r' != a_pServer->GetByte() ||
            '\n' != a_pServer->GetByte())
        {
            throw ServerSocket::Exception("bad response");
        }

        ++nFound;
    }

    return nFound;
}