Beispiel #1
0
    // 功能:读取一个字符,优化的函数
    // 参数:chBuf - 输出字符地址
    //       nPrepareSize - 预读取的长度, 小于等于零表示按最大缓冲读取
    public int ReceiveChar(byte [] chBuf, int nPrepareSize = -1)
    {
        if (m_nReadPos < m_nPrepareReadSize)
        {
            chBuf[0] = m_PrepareReadBuf[m_nReadPos];
            ++m_nReadPos;
            return(1);
        }
        if (nPrepareSize <= 0)
        {
            nPrepareSize = HTTP_CACHE_SIZE;
        }
        else if (nPrepareSize > HTTP_CACHE_SIZE)
        {
            nPrepareSize = HTTP_CACHE_SIZE;
        }

        int nRecLen = m_tcp.Receive(m_PrepareReadBuf, nPrepareSize);

        if (nRecLen <= 0)
        {
            return(nRecLen);
        }
        m_nPrepareReadSize = nRecLen;
        m_nReadPos         = 1;
        chBuf[0]           = m_PrepareReadBuf[0];
        return(1);
    }
Beispiel #2
0
    void  BeginRecive()
    {
        int nRecvSize = 0;

        while (m_tcp.IsConnect())
        {
            nRecvSize = m_tcp.Receive(m_RecvBuffer, 4096);
            if (nRecvSize > 0)
            {
                OnReceiveBuf(m_RecvBuffer, nRecvSize);
            }
            else
            {
                Quit();
            }
        }
    }