Exemple #1
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;
}
Exemple #2
0
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;
}
Exemple #3
0
CStr CBaseFile::GetSysFolder( oexBOOL x_bShared, oexINT x_nFolderId, oexINT x_nMaxLength )
{
	// Get the folder
	switch( x_nFolderId )
	{
		case eFidNone :
			break;

		case eFidTemp :
		{
			const char *pTmp;
			if ( !( pTmp = getenv( "TMPDIR" ) ) 
				 && !( pTmp = getenv( "TEMP" ) )
				 && !( pTmp = getenv( "TMP" ) ) 
			   )
				return oexT( "/tmp" );

			return oexMbToStr( pTmp );

		} break;

		case eFidSystem :
			return CBaseFile_GetHome();

		case eFidUserOs :
			return oexT( "/sys" );

		case eFidCurrent :
		{
			// Ask for the current working directory
			CStr8 s;
			char *cwd = s.Allocate( oexSTRSIZE );
			if ( !cwd || !getcwd( cwd, oexSTRSIZE ) || !*cwd )
				s.Destroy();

			return s;

		} break;

		case eFidRoot :
		case eFidDefDrive :
			return oexT( "/" );

		case eFidFonts :
			return oexT( "/usr/share/fonts/truetype/msttcorefonts" );

		case eFidSettings :
			if ( x_bShared )
				return oexT( "/var/lib" );
			return oexBuildPath( CBaseFile_GetHome(), oexT( ".config" ) );

		case eFidDesktop :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Desktop" ) );

		case eFidDownloads :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Downloads" ) );

		case eFidTemplates :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Templates" ) );

		case eFidPublic :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Public" ) );

		case eFidDocuments :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Documents" ) );

		case eFidMusic :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Music" ) );

		case eFidPictures :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Pictures" ) );

		case eFidVideo :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Videos" ) );

		default :
			break;

	} // end switch

	return oexT( "" );
}