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


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

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


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

示例1: setFile

bool KFile::setFile(KData fullFilePath, int mode)
{
	if (m_bIsOpen)
	{
		fclose (m_hFile);
		m_bIsOpen = false;
	}

#ifndef WIN32
	replaceAll(fullFilePath);
#endif

	if (fullFilePath.find("/") == -1)			//斜杠……
	{
		m_kFilePath = "./";
		m_kFileName = fullFilePath;
	}
	else
	{
		KData tStr = fullFilePath;
		if (tStr[tStr.length() - 1] == '/')
		{
			return false;
		}
		else
		{
			int pos = tStr.findlast("/");
			m_kFilePath = tStr.substr(0, pos + 1);
			m_kFileName = tStr.substr(pos + 1, tStr.length() - pos - 1);
		}
	}
	return open(mode);
}
开发者ID:korman,项目名称:Temp,代码行数:33,代码来源:KFile.cpp

示例2: createDir

bool KDirectory::createDir(const KData& dir)
{
	int pos = 0;
	while (true)
	{
		if ((pos = dir.find("/", pos)) == -1)
			pos = dir.length();
		KData dtDir = dir.substr(0, pos);
		pos++;
		if (!dtDir.isEmpty())
		{
			if (!isDirectoryExist(dtDir))
			{
				/*
				 if ( -1 == mkdir(dtDir.getData(),S_IRWXU|S_IRWXG|S_IRWXO) )
				 {
				 return false;
				 }
				 */
				if (MKDIR(dtDir.getData()) != 0)
				{
					return false;
				}

			}
		}
		if (pos >= (int) dir.length())
			break;
	}
	return true;
}
开发者ID:korman,项目名称:Temp,代码行数:31,代码来源:KDirectory.cpp

示例3: vCpLog

void vCpLog( int pri, const char* file, int line, const char* fmt, va_list ap )
{
    assert( pri >= 0 && pri <= LAST_PRIORITY );

    char datebuf[ DATEBUF_SIZE ];
	memset(datebuf, 0, DATEBUF_SIZE);
    int datebufCharsRemaining;

    struct timeval tv;
    struct timezone tz;
    int result = gettimeofday( &tv, &tz );
    
    if( result == -1 )
    {
	    datebuf [0] = '\0';
    }
    else
    {
		const time_t timeInSeconds = (time_t) tv.tv_sec;
		strftime( datebuf, DATEBUF_SIZE, "%m-%d %H:%M:%S", localtime ( &timeInSeconds ) );
    }
    char msbuf[10];

    sprintf( msbuf, ".%3.3d", (int)(tv.tv_usec/1000) );
    datebufCharsRemaining = DATEBUF_SIZE - strlen( datebuf );
    strncat( datebuf, msbuf, datebufCharsRemaining - 1 );
    datebuf[DATEBUF_SIZE - 1] = '\0';

	if( bConnServer )
	{
		char outBuff[2048];
		memset(outBuff, 0, 2048);
		KData ret = "[";
		ret = ret + KData(datebuf) + KData("]") + KData(priNameShort[pri]) + KData(" ");
		vsprintf( outBuff, fmt, ap );
		ret += outBuff;
		LogPack *pLogPack = (LogPack*)outBuff;
		pLogPack->lLogMsgSize = htonl( ret.length() ) ;
		strcpy( pLogPack->strLogMsg, ret.getDataBuf() );
		spClientSock->transmit( (char*)pLogPack, sizeof( long )+ret.length() );
	}

	if( mainLogFunc == NULL )
	{
		fprintf( cpLogFd, "[%s] %s: ", datebuf, priNameShort[pri] );
		vfprintf( cpLogFd, fmt, ap );
		fprintf( cpLogFd, "\n" );
		fflush( cpLogFd );
	}
	else
	{
		char outBuff[2048];
		memset(outBuff, 0, 2048);
		KData ret = "[";
		ret = ret + KData(datebuf) + "]" + priNameShort[pri] + "  ";
		vsprintf( outBuff, fmt, ap );
		ret += outBuff;
		mainLogFunc( ret, pri );
	}
}
开发者ID:chaosren,项目名称:HHHH,代码行数:60,代码来源:cpLog.cpp

示例4: write

int KFile::write(const KData& data)
{
	const char* pKData = data.getDataBuf();
	int len = data.length();
	int iWrited = 0;
	while (iWrited < len)
	{
		int iRet = write((unsigned char*) (pKData + iWrited), len - iWrited);
		if (iRet <= 0)
			break;
		iWrited += iRet;
	}
	return iWrited;
}
开发者ID:korman,项目名称:Temp,代码行数:14,代码来源:KFile.cpp

示例5: atoi

void
KNetworkAddress::setHostName( const KData& theAddress )
{
    const char* cstrAddress;
    KData sAddress, sPort;
    unsigned int length = theAddress.length();
    unsigned int colonPos = length;
    cstrAddress = theAddress.getData();
    for ( int i = 0; *cstrAddress != '\0'; cstrAddress++, i++ )
    {
        if ( *cstrAddress == ':' )
        {
            colonPos = i;
            break;
        }
    }
    if ( colonPos != length )
    {
        sAddress = theAddress.substr( 0, colonPos );
        sPort = theAddress.substr( colonPos+1, length-colonPos-1 );
        colonPos = atoi( sPort.getData() );
        if ( colonPos )
        {
            aPort = colonPos;
        }
        else
        {
        }
    }
    else // No ':' in input string;
    {
        sAddress = theAddress;
    }
    rawHostName = sAddress;
    ipAddressSet = false;
}
开发者ID:chaosren,项目名称:HHHH,代码行数:36,代码来源:KNetworkAddress.cpp

示例6: getHttpFileLength

int KHttp::getHttpFileLength(const KData & fullUrl)
{
	KData server;
	KData httpFile;
	KData dtFullUrl = fullUrl;

	if (isEqualNoCase(dtFullUrl.substr(0, 7), "http://"))
	{
		dtFullUrl = dtFullUrl.substr(7);
	}

	int pos = dtFullUrl.find("/");
	if (pos == -1)
	{
		return -1;
	}
	else
	{
		server = dtFullUrl.substr(0, pos);
		httpFile = dtFullUrl.substr(pos);
	}

	m_bChunked = false;
	m_iWriteLen = 0;
	m_iLength = 0;
	m_clientSock.close();
	m_kCnnect.close();

	_respHeadMap.clear();
	m_iNotifyPos = 0;
	m_iNotifyGap = 0;
	m_iContentLength = 0;
	m_iStatusCode = 0;
	bool bGet = (_paramMap.size() == 0);

	KFile file;
	KData httpRequest;
	KData dtPost;

	if (bGet)
	{
		httpRequest = "GET ";
	}
	else
	{
		httpRequest = "POST ";
		map<KData, KData>::iterator iter;
		for (iter = _paramMap.begin(); iter != _paramMap.end(); iter++)
		{
			if (iter != _paramMap.begin())
				dtPost += "&";
			dtPost += iter->first;
			dtPost += "=";
			dtPost += iter->second;
		}
	}

	httpRequest += httpFile;
	httpRequest += " HTTP/1.1";
	httpRequest += CRLF;
	httpRequest += "Host: ";
	httpRequest += server;
	httpRequest += CRLF;
	httpRequest += "Accept: */*";
	httpRequest += CRLF;
	if (!m_dtUserAgent.isEmpty())
	{
		httpRequest += "User-Agent: ";
		httpRequest += m_dtUserAgent;
		httpRequest += CRLF;
	}

	httpRequest += "Pragma: no-cache";
	httpRequest += CRLF;
	httpRequest += "Cache-Control: no-cache";
	httpRequest += CRLF;
	httpRequest += "Connection: close";
	httpRequest += CRLF;

	if (!bGet)
	{
		httpRequest += "Content-Type: application/x-www-form-urlencoded";
		httpRequest += CRLF;
		httpRequest += "Content-Length: ";
		httpRequest += KData((int) dtPost.length());
		httpRequest += CRLF;
	}

	httpRequest += CRLF;

	char buff[MTU] =
	{ 0 };

	m_clientSock.setServer(server, 80);
	if (!m_clientSock.connect())
	{
		return 0;
	}

	m_kCnnect = m_clientSock.getConn();
//.........这里部分代码省略.........
开发者ID:korman,项目名称:Temp,代码行数:101,代码来源:KHttp.cpp

示例7: getHttpFile

int KHttp::getHttpFile(const KData& kServer, const KData& kHttpFile,
		const KData& kSaveFile, int nStartPos)
{
	LOGD("Entry getHttpFile");
	m_dtHttpServer = kServer;
	m_dtHttpFile = kHttpFile;
	m_bChunked = false;
	m_iWriteLen = nStartPos;
	m_iLength = 0;
	m_clientSock.close();
	m_kCnnect.close();

	_respHeadMap.clear();
	m_iNotifyPos = 0;
	m_iNotifyGap = 0;
	m_iContentLength = 0;
	m_iStatusCode = 0;
	bool bGet = (_paramMap.size() == 0);

	KFile kFile;
	KData kHttpRequest;
	KData kDataPost;

	if (bGet)
	{
		kHttpRequest = "GET ";
	}
	else
	{
		kHttpRequest = "POST ";
		map<KData, KData>::iterator iter;
		for (iter = _paramMap.begin(); iter != _paramMap.end(); iter++)
		{
			if (iter != _paramMap.begin())
				kDataPost += "&";
			kDataPost += iter->first;
			kDataPost += "=";
			kDataPost += iter->second;
		}
	}

	kHttpRequest += kHttpFile;
	kHttpRequest += " HTTP/1.1";
	kHttpRequest += CRLF;
	kHttpRequest += "Host: ";
	kHttpRequest += kServer;
	kHttpRequest += CRLF;
	kHttpRequest += "Accept: */*";
	kHttpRequest += CRLF;
	if (!m_dtUserAgent.isEmpty())
	{
		kHttpRequest += "User-Agent: ";
		kHttpRequest += m_dtUserAgent;
		kHttpRequest += CRLF;
	}

	if (nStartPos > 0)
	{
		kHttpRequest += "RANGE: bytes=";
		kHttpRequest += nStartPos;
		kHttpRequest += "-";
		kHttpRequest += CRLF;
	}

	kHttpRequest += "Pragma: no-cache";
	kHttpRequest += CRLF;
	kHttpRequest += "Cache-Control: no-cache";
	kHttpRequest += CRLF;
	kHttpRequest += "Connection: close";
	kHttpRequest += CRLF;

	if (!bGet)
	{
		kHttpRequest += "Content-Type: application/x-www-form-urlencoded";
		kHttpRequest += CRLF;
		kHttpRequest += "Content-Length: ";
		kHttpRequest += KData((int) kDataPost.length());
		kHttpRequest += CRLF;
	}

	kHttpRequest += CRLF;

	char szBuffer[MTU] = {0};

	if (m_dtHttpProxy.isEmpty())
	{
		LOGD("Connect to Server:  %s", kServer.getData() );
		m_clientSock.setServer(kServer, 80);
	}
	else
	{
		LOGD("Connect to Server:  %s", m_dtHttpProxy.getData() );
		m_clientSock.setServer(m_dtHttpProxy, 80);
	}
	m_clientSock.initSocket();
	if (!m_clientSock.connect())
	{
		LOGERROR("m_clientSock.connect() failed");
		return -1;
	}
//.........这里部分代码省略.........
开发者ID:korman,项目名称:Temp,代码行数:101,代码来源:KHttp.cpp


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