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; }
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; }
CStr8 CSerialPort::Read( oexSIZE_T x_nSize ) {_STT(); SSerialPortSettings *pS = (SSerialPortSettings*)m_pSettings; if ( !pS || 0 > pS->fd ) return CStr8(); CStr8 s; oexSTR8 p = s.Allocate( x_nSize ); if ( !p ) return CStr8(); // Attempt to read data from port int nRead = read( pS->fd, p, x_nSize ); if ( 0 > nRead ) { m_nError = errno; return CStr8(); } // end if // How many bytes did we read? s.SetLength( nRead ); return s; }