int ChunkOutputStream::chunkedWrite( IOVec &iov, int &headerTotal,
                            const char * pBuf, int size)
{
    //printf( "****ChunkOutputStream::chunkedWrite()\n" );
    IOVec::iterator iter = iov.end();
    int bytes = buildIovec( iov, pBuf, size );
    int total = bytes + headerTotal;
    int ret = m_pOS->writev( iov, total );
    assert( m_iCurSize == 0 );
    if ( ret >= total )
    {
        iov.clear();
        headerTotal = 0;
        m_iCurSize = 0;
        return size;
    }
    else if ( ret >= 0 )
    {
        if( ret >= headerTotal )
        {
            if ( ret == headerTotal )
            {
                iov.clear();
            }
            else
            {
                ret -= headerTotal;
                m_iTotalPending = bytes - ret;
                iov.setBegin( iter );
                iov.finish( ret );
                m_pLastBufBegin = pBuf;
                m_iLastBufLen = size;
            }
            headerTotal = 0;
        }
        else
        {
            if ( ret )
            {
                headerTotal -= ret;
                iov.finish( ret );
            }
            iov.setEnd( iter );
        }
        return 0;
    }
    else
        iov.setEnd( iter );
    return ret;
}
示例#2
0
    void CheckIoHeader(IOVec io, char *phBuf)
    {
        IOVec::iterator it;
        unsigned char *p = NULL;
        char *ph = phBuf;

//printf("->&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");


        for (it = io.begin(); it != io.end(); ++it)
        {
            p = (unsigned char *)it->iov_base;
            printf("Check: %.*s, %.*s\n", it->iov_len, p, it->iov_len, ph);
            CHECK(strncasecmp((const char *)p, ph, it->iov_len) == 0);
            if (strncasecmp((const char *)p, ph, it->iov_len) != 0)
                printf("p:\n%.*s\nph:\n%.*s\n", it->iov_len, p, it->iov_len, ph);
            ph += it->iov_len;
        }

//printf("<-&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");
    }
示例#3
0
    void DisplayBothHeader(IOVec io, int format, short count,
                           HttpRespHeaders * pRespHeaders)
    {
        IOVec::iterator it;
        unsigned char *p = NULL;
        it = io.begin();
        p = (unsigned char *)it->iov_base;
        //return;//comment this out to view header data


        for (it = io.begin(); it != io.end(); ++it)
        {
            p = (unsigned char *)it->iov_base;
            for (unsigned int i = 0; i < it->iov_len; ++i)
            {
                if (format  != 0)
                    printf("%02X ", p[i]);
                else
                    printf("%c", p[i]);
            }
        }
        printf("\r\nplain http Count = %d\r\n======================================================\r\n",
               count);

        displaySpdyHeaders(pRespHeaders);

//     if (format != 0)
//     {
//         AutoBuf buf;
//         for (it = io.begin(); it != io.end(); ++it)
//         {
//             buf.append( (const char *)it->iov_base, it->iov_len);
//         }
//
//         if (format ==  1)
//         {
//             char *p = buf.begin();
//             short *tempNumS;
//             short tempNum;
//
//             for (int j=0; j<count; ++j)
//             {
//                 tempNumS = (short *)p;
//                 tempNum = ntohs(*tempNumS);
//                 p += 2;
//                 for (int n=0; n<tempNum; ++n){
//                     printf("%c", *(p + n));
//                 }
//                 printf(": ");
//                 p += tempNum;
//
//                 tempNumS = (short *)p;
//                 tempNum = ntohs(*tempNumS);
//                 p += 2;
//                 for (int n=0; n<tempNum; ++n){
//                     if (*(p + n) != 0)
//                         printf("%c", *(p + n));
//                     else
//                         printf("\r\n\t");
//                 }
//                 printf("\r\n");
//                 p += tempNum;
//             }
//         }
//         else
//         {
//             char *p = buf.begin();
//             int32_t *tempNumS;
//             int32_t tempNum;
//
//             for (int j=0; j<count; ++j)
//             {
//                 tempNumS = (int32_t *)p;
//                 tempNum = ntohl(*tempNumS);
//                 p += 4;
//                 for (int n=0; n<tempNum; ++n){
//                     printf("%c", *(p + n));
//                 }
//                 printf(": ");
//                 p += tempNum;
//
//                 tempNumS = (int32_t *)p;
//                 tempNum = ntohl(*tempNumS);
//                 p += 4;
//                 for (int n=0; n<tempNum; ++n){
//                     if (*(p + n) != 0)
//                         printf("%c", *(p + n));
//                     else
//                         printf("\r\n\t");
//                 }
//                 printf("\r\n");
//                 p += tempNum;
//             }
//         }
//
//         printf("\r\n*******************************************************************\r\n\r\n");
//
//     }

    }