当前位置: 首页>>代码示例>>C++>>正文


C++ t_string::length方法代码示例

本文整理汇总了C++中t_string::length方法的典型用法代码示例。如果您正苦于以下问题:C++ t_string::length方法的具体用法?C++ t_string::length怎么用?C++ t_string::length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在t_string的用法示例。


在下文中一共展示了t_string::length方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LookupHost

int CIpAddress::LookupHost( const t_string &x_sServer, unsigned int x_uPort, unsigned int x_uType )
{
#if defined( HTM_NOSOCKET2 )
	return 0;
#else
    // Lose old info
    Destroy();

    // Ensure we have a valid pointer
    if ( !x_sServer.length() )
        return 0;

	// First try to interpret as dot address
	unsigned long uAddr = inet_addr( x_sServer.c_str() );
	if ( INADDR_NONE == uAddr )
    {
        LPHOSTENT pHe = gethostbyname( x_sServer.c_str() );

        if ( !pHe )
            return 0;

        LPIN_ADDR pia = (LPIN_ADDR)*pHe->h_addr_list;
        if ( !pia )
            return 0;

        // Grab the address
        uAddr = *(DWORD*)&pia->S_un.S_addr;

    } // end if

    SetRawAddress( ntohl( uAddr ), x_uPort, x_uType );

    return 1;
#endif
}
开发者ID:summit4you,项目名称:QThybrid,代码行数:35,代码来源:sockets-windows.hpp

示例2: GetDomainName

CIpAddress::t_string CIpAddress::GetDomainName( const t_string &x_sServer )
{
	CIpAddress::t_string sRet;

	// Load netapi32.dll
	HMODULE hLib = LoadLibrary( tcT( "netapi32.dll" ) );
	if ( !hLib )
		return sRet;

	// Get function pointers
	pfn_NetApiBufferFree pNetApiBufferFree = (pfn_NetApiBufferFree)GetProcAddress( hLib, tcT( "NetApiBufferFree" ) );
	pfn_NetWkstaGetInfo pNetWkstaGetInfo = (pfn_NetWkstaGetInfo)GetProcAddress( hLib, tcT( "NetWkstaGetInfo" ) );

	// Attempt to read the domain name
	WKSTA_INFO_100 *pwi100 = 0;
	if ( pNetWkstaGetInfo
		 && !pNetWkstaGetInfo( x_sServer.length() ? (LPWSTR)tcStr2Wc( x_sServer ).c_str() : 0, 100, (LPBYTE*)&pwi100 ) )
		if ( pwi100 && pwi100->wki100_langroup )
			sRet = tcWc2Str( pwi100->wki100_langroup );

	// Free buffer
	if ( pNetApiBufferFree && pwi100 )
		pNetApiBufferFree( pwi100 );

	// Free library
	FreeLibrary( hLib );

	// Send the domain name along
	return sRet;
}
开发者ID:summit4you,项目名称:QThybrid,代码行数:30,代码来源:sockets-windows.hpp

示例3: LookupUri

int CIpAddress::LookupUri( const t_string &x_sUrl, unsigned int x_uPort, unsigned int x_uType )
{
    // Lose old info
    Destroy();

    // Ensure we have a valid pointer
    if ( !x_sUrl.length() )
        return 0;

    // Crack the url
    t_pb8 pbUri = parser::DecodeUri< t_pb8 >( x_sUrl );
    if ( !pbUri.size() )
        return 0;

    // Did we get a host name?
    if ( !pbUri[ "host" ].length() )
        return 0;

    // Get the port
    if ( !x_uPort )
        x_uPort = pbUri[ "port" ].ToLong();

    // Save the type
    m_uType = x_uType;

    return LookupHost( pbUri[ "host" ].str(), x_uPort );
}
开发者ID:AmberSandDan,项目名称:htmapp,代码行数:27,代码来源:sockets.cpp

示例4: SetDotAddress

// +++ Make IPv6 safe
int CIpAddress::SetDotAddress( const t_string &x_sDotAddress, unsigned int x_uPort, unsigned int x_uType )
{
    if ( !x_sDotAddress.length() )
        return 0;

    // Convert the dot address
    u_long ip = ntohl( inet_addr( x_sDotAddress.c_str() ) );
    if ( INADDR_NONE == ip )
        return 0;

    SetRawAddress( ip, x_uPort, x_uType );

    return 1;
}
开发者ID:AmberSandDan,项目名称:htmapp,代码行数:15,代码来源:sockets-posix.hpp

示例5: Connect

int CIpSocket::Connect( const t_string &x_sAddress, unsigned int x_uPort )
{
	if ( !x_sAddress.length() )
        return 0;

	// Punt if not initialized
	if ( !IsInitialized() )
		return 0;

	CIpAddress addr;

    // Were we passed a URL?
    if ( !x_uPort && addr.LookupUri( x_sAddress ) )
		return Connect( addr );

	// Lookup the host address
    if ( addr.LookupHost( x_sAddress, x_uPort ) )
		return Connect( addr );

	return 0;
}
开发者ID:AmberSandDan,项目名称:htmapp,代码行数:21,代码来源:sockets.cpp

示例6: Write

    DWORD Client::Write(t_string write_buffer)
    {
        if (eState_ != STATE::started)
        {
            return ERROR_NOT_FOUND;
        }

        DWORD cbWritten;

        EnterCriticalSection(&csPipe_Write_);

            BOOL bSuccess = WriteFile ( 
                                            hPipe_,                                                 // pipe handle 
                                            write_buffer.c_str(),                                   // message 
                                            write_buffer.length() * 
                                            sizeof(t_string::traits_type::char_type),               // message length 
                                            &cbWritten,                                             // bytes written 
                                            NULL                                                    // not overlapped 
                                        );

        LeaveCriticalSection(&csPipe_Write_);

        return bSuccess ? ERROR_SUCCESS : GetLastError();
    }
开发者ID:Andreyko,项目名称:NamedPipes,代码行数:24,代码来源:Client.cpp

示例7: Write

    DWORD Base::Write(const t_string & write_buffer, HANDLE pipe_handle, CRITICAL_SECTION & write_critical_section)
    {
        if (eState_ != STATE::started)
        {
            return ERROR_NOT_FOUND;
        }    

        EnterCriticalSection(&write_critical_section);

            DWORD cbWritten;

            BOOL bSuccess = WriteFile ( 
                                            pipe_handle,                                            // pipe handle 
                                            write_buffer.c_str(),                                   // message 
                                            write_buffer.length() * 
                                            sizeof(t_string::traits_type::char_type),               // message length 
                                            &cbWritten,                                             // bytes written 
                                            NULL                                                    // not overlapped 
                                        );

        LeaveCriticalSection(&write_critical_section);

        return bSuccess ? ERROR_SUCCESS : GetLastError();
    }
开发者ID:Andreyko,项目名称:NamedPipes,代码行数:24,代码来源:Base.cpp

示例8: LookupHost

int CIpAddress::LookupHost( const t_string &x_sServer, unsigned int x_uPort, unsigned int x_uType )
{
    // Lose old info
    Destroy();

    // Ensure we have a valid pointer
    if ( !x_sServer.length() )
        return 0;

// +++ Get this working eventually
// #if !defined( HTM_USE_GETHOSTBYNAME )
#if 0

	in_addr ip4;
	if ( inet_pton( PF_INET, x_sServer.c_str(), &ip4 ) )
	{	SetRawAddress( ntohl( *(unsigned long*)&ip4.s_addr ), x_uPort, x_uType );
		return 1;
	} // end if

	struct addrinfo hints, *addr = 0;
	memset( &hints, 0, sizeof( hints ) );
	hints.ai_family = PF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_flags = AI_CANONNAME;

	int rval = 0;
    if ( rval = getaddrinfo( x_sServer.c_str(), 0, &hints, &addr ) )
		return 0;

	int max = 128;
	while ( !addr && max-- )
	{
		switch( addr->ai_family )
		{
			case AF_INET :
			{
				sockaddr_in *psai = (sockaddr_in*)addr->ai_addr;
				in_addr *pia = &psai->sin_addr;
			    SetRawAddress( ntohl( *(unsigned long*)&pia->s_addr ), x_uPort, x_uType );
			    return 1;

			} break;

			case AF_INET6 :
			{
				// +++ Add v6 support
				sockaddr_in6 *psai = (sockaddr_in6*)addr->ai_addr;
				sin6_addr *pia6 = &psai->sin6_addr;

			} break;

		} // end switch

		if ( addr == addr->ai_next )
			addr = 0;
		else
			addr = addr->ai_next;

	} // end while

	return 0;

#else

	// First try to interpret as dot address
	unsigned int uAddr = inet_addr( x_sServer.c_str() );
	if ( INADDR_NONE != uAddr )
	{   SetRawAddress( ntohl( uAddr ), x_uPort, x_uType );
		return 1;
	} // end if

    struct hostent *pHe;
	do { pHe = gethostbyname( x_sServer.c_str() );
	} while ( !pHe && EINTR == h_errno );

    if ( !pHe || !pHe->h_addr_list )
		return 0;

    in_addr *pia = (in_addr*)*pHe->h_addr_list;
    if ( !pia )
		return 0;

    SetRawAddress( ntohl( *(unsigned int*)&pia->s_addr ), x_uPort, x_uType );

    return 1;

#endif

}
开发者ID:AmberSandDan,项目名称:htmapp,代码行数:89,代码来源:sockets-posix.hpp


注:本文中的t_string::length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。