Esempio n. 1
0
int xRedisServerBase::SendBulkReply(xRedisConnectorBase *pConnector, const std::string &strResult)
{
    NetPrintf(pConnector, "$%zu\r\n", strResult.size());
    SendData(pConnector, strResult.c_str(), strResult.size());
    SendData(pConnector, "\r\n", 2);
    return 0;
}
Esempio n. 2
0
int xRedisServerBase::SendMultiBulkReply(xRedisConnectorBase *pConnector, const std::vector<std::string> &vResult)
{
    NetPrintf(pConnector, "*%zu\r\n", vResult.size());
    for (size_t i = 0; i < vResult.size(); ++i) {
        SendBulkReply(pConnector, vResult[i]);
    }
    return 0;
}
Esempio n. 3
0
void NetPrintMemCode(const void *pMem, int32_t iSize, const char *pTitle)
{
    static const char _hex[] = "0123456789ABCDEF";
    char strOutput[128];
    int32_t iBytes, iOutput = 2;

    memset(strOutput, ' ', sizeof(strOutput)-1);
    strOutput[sizeof(strOutput)-1] = '\0';

    NetPrintf(("dirtylib: dumping memory for object %s (%d bytes)\n", pTitle, iSize));

    for (iBytes = 0; iBytes < iSize; iBytes++, iOutput += 2)
    {
        unsigned char cByte = ((unsigned char *)pMem)[iBytes];
        strOutput[iOutput]   = _hex[cByte>>4];
        strOutput[iOutput+1] = _hex[cByte&0xf];
        strOutput[(iOutput/2)+40] = isprint(cByte) ? cByte : '.';
        if (iBytes > 0)
        {
            if (((iBytes+1) % 16) == 0)
            {
                strOutput[(iOutput/2)+40+1] = '\0';
                NetPrintf(("%s\n", strOutput));
                memset(strOutput, ' ', sizeof(strOutput)-1);
                strOutput[sizeof(strOutput)-1] = '\0';
                iOutput = 0;
            }
            else if (((iBytes+1) % 4) == 0)
            {
                iOutput++;
            }
        }
    }

    if ((iBytes % 16) != 0)
    {
        strOutput[(iOutput/2)+40+1] = '\0';
        NetPrintf(("%s\n", strOutput));
    }
}
Esempio n. 4
0
void NetPrintfVerboseCode(int32_t iVerbosityLevel, int32_t iCheckLevel, const char *pFormat, ...)
{
    va_list Args;
    char strText[1024];

    va_start(Args, pFormat);
    vsnzprintf(strText, sizeof(strText), pFormat, Args);
    va_end(Args);

    if (iVerbosityLevel > iCheckLevel)
    {
        NetPrintf(("%s", strText));
    }
}
Esempio n. 5
0
void NetPrintWrapCode(const char *pString, int32_t iWrapCol)
{
    const char *pTemp, *pEnd, *pEqual, *pSpace;
    char strTemp[256] = "   ";
    uint32_t bDone;
    int32_t iLen;

    for (bDone = FALSE; bDone == FALSE; )
    {
        for (pTemp=pString, pEnd=pTemp+iWrapCol, pSpace=NULL, pEqual=NULL; (pTemp < pEnd); pTemp++)
        {
            if ((*pTemp == ' ') || (*pTemp == '\t'))
            {
                pSpace = pTemp;
            }

            if (*pTemp == '=')
            {
                pEqual = pTemp;
            }

            if ((*pTemp == '\n') || (*pTemp == '\0'))
            {
                break;
            }
        }
        
        if (pTemp == pEnd)
        {
            if (pSpace != NULL)
            {
                pTemp = pSpace;
            }
            else if (pEqual != NULL)
            {
                pTemp = pEqual;
            }
        }

        iLen = pTemp - pString + 1;
        strncpy(strTemp + 3, pString, iLen);
        if (*pTemp == '\0')
        {
            strTemp[iLen+2] = '\n';
            strTemp[iLen+3] = '\0';
            bDone = TRUE;
        }
        else if ((*pTemp != '\n') && (*pTemp != '\r'))
        {
            strTemp[iLen+3] = '\n';
            strTemp[iLen+4] = '\0';
        }
        else
        {
            strTemp[iLen+3] = '\0';
        }

        NetPrintf(("%s", strTemp));

        pString += iLen;
    }
}
Esempio n. 6
0
int xRedisServerBase::SendIntReply(xRedisConnectorBase *pConnector, int64_t ret)
{
    return NetPrintf(pConnector, ":%" PRId64 "\r\n", ret);
}
Esempio n. 7
0
int xRedisServerBase::SendErrReply(xRedisConnectorBase *pConnector, const char *errtype, const char *errmsg)
{
    return NetPrintf(pConnector, "-%s %s\r\n", errtype, errmsg);
}
Esempio n. 8
0
int xRedisServerBase::SendNullReply(xRedisConnectorBase *pConnector)
{
    return NetPrintf(pConnector, "$-1\r\n");
}
Esempio n. 9
0
int xRedisServerBase::SendStatusReply(xRedisConnectorBase *pConnector, const char* str)
{
    return NetPrintf(pConnector, "+%s\r\n", str);
}