Exemple #1
0
oexBOOL CCircBuf::Peek( CStr8 &x_sStr, t_size x_uMax )
{
	// Lock the buffer
	oexAutoLock ll( &m_lock );
	if ( !ll.IsLocked() )
        return oexFALSE;

    // Zero means all of it
    if ( !x_uMax )
        x_uMax = GetMaxRead();

    // Anything to read?
    if ( !x_uMax )
        return oexFALSE;

    // Allocate memory
    if ( !x_sStr.OexAllocate( x_uMax ) )
        return oexFALSE;

	t_size uRead = 0;

	// Read the string from the buffer
	Peek( x_sStr._Ptr(), x_uMax, &uRead );

    // Ensure didn't read more than we should have
    oexASSERT( x_uMax >= uRead );

    // Don't assume it's NULL terminated
    x_sStr.SetLength( uRead );

    return oexTRUE;
}
Exemple #2
0
CStr8 CIpSocket::Recv( oexUINT x_uMax, oexUINT x_uFlags )
{
    // Do we have a size limit?
    if ( x_uMax )
    {
        // Allocate buffer
        CStr8 sBuf;
        sBuf.Allocate( x_uMax );

        // Attempt to read data
        oexUINT uRead = Recv( sBuf._Ptr(), x_uMax, oexNULL, x_uFlags );

        // Accept as the length
        sBuf.SetLength( uRead );

        return sBuf;

    } // end if

    // Allocate buffer
    CStr8 sBuf;
    oexUINT uRead = 0, uOffset = 0;

    // Allocate space
    if ( !sBuf.OexAllocate( oexSTRSIZE ) )
        return sBuf;

    // Read all available data
    while ( 0 < ( uRead = Recv( sBuf._Ptr( uOffset ), oexSTRSIZE, oexNULL, x_uFlags ) )
            && (oexINT)uRead >= oexSTRSIZE )
    {
		if ( (oexINT)uRead > oexSTRSIZE )
			uRead = oexSTRSIZE;

        // Allocate more space
        uOffset += uRead;
        if ( !sBuf.Allocate( uOffset + oexSTRSIZE ) )
            return sBuf;

    } // end while

    // Set the length
    sBuf.SetLength( uOffset + uRead );

    return sBuf;
}