[阅读: 823] 2005-02-04 07:21:08
			
				// 返回值:
//  0, 正常
//  如果是网络出错,则抛出 CSocketException 异常
int CTcpSocket::SendEx(const char* szBuf, int nBufLen, int nFlag)
{
	int nCode = 0;
	int nSended = 0;
	const char* pszBuf = szBuf;
	if (m_hSocket<=0)
		commlogInt(loglevel5,"异常:m_hSocket=",m_hSocket);
	while (true)
	{
		nSended = send(m_hSocket, pszBuf, nBufLen, nFlag);
		if (nSended < 0) // 网络错误
		{
			nCode = CSocketException::GetOsCode();
			throw CSocketException(nCode, CSocketException::GetOsMsg(nCode).c_str());
		}
		else
		{
			// 发送完毕则终止循环
			if (nSended == nBufLen)
				break;
			
			nBufLen -= nSended;
			pszBuf += nSended;
		}
	}
	
	return 0;
}