}
void CNetIOBuffer::ResetIoBuffer()
{
EnterCriticalSection(&m_cs);
m_nLength = 0;
memset(m_pbinData,0,m_nTotalLength);
LeaveCriticalSection(&m_cs);
}
BOOL CNetIOBuffer::CopyData(const LPBYTE lbbyte, int nLength)
{
if( nLength > MAX_BUFFER_LENGTH )
return FALSE;
ResetIoBuffer();
EnterCriticalSection(&m_cs);
memcpy(m_pbinData, lbbyte, nLength );
m_nLength = nLength;
LeaveCriticalSection(&m_cs);
return TRUE;
}
BOOL CNetIOBuffer::ConcatData(const LPBYTE lbbyte, int nLength)
{
if( m_nLength + nLength > MAX_BUFFER_LENGTH )
return FALSE;
EnterCriticalSection(&m_cs);
memcpy(m_pbinData+m_nLength, lbbyte, nLength );
m_nLength += nLength;
LeaveCriticalSection(&m_cs);
return TRUE;
}
int CNetIOBuffer::GetLength() const
{
return m_nLength;
}
BOOL CNetIOBuffer::SetLength(int nLen)
{
if( nLen > MAX_BUFFER_LENGTH )
return FALSE;
EnterCriticalSection(&m_cs);
m_nLength = nLen;
LeaveCriticalSection(&m_cs);
return TRUE;
}
LPBYTE CNetIOBuffer::GetCurPos()
{
if( m_nLength < MAX_BUFFER_LENGTH )
return (m_pbinData+m_nLength);
else
return NULL;
}
CNetIOBuffer:: operator LPBYTE() const
{
return m_pbinData;
}
int CNetIOBuffer::GetRemainLen()
{
return MAX_BUFFER_LENGTH - m_nLength;
}
BOOL CNetIOBuffer::IsEmpty() const
{
return m_nLength == 0;
}
const CNetIOBuffer& CNetIOBuffer:: operator=(const CNetIOBuffer& buffSrc)
{
if(&buffSrc!=this)
{
CopyData(buffSrc, buffSrc.GetLength());
}
return *this;
}
12.发送数据时候一般是系统缓冲区满以后才发送,现在设置为只要系统
缓冲区有数据就立刻发送:
BOOL bNodelay=TRUE;
SetSockOpt(s,IPPROTO_TCP,TCP_NODELAY,(const char*)&bNodelayt,sizeof(BOOL));
附加:
setoptsock()这个函数 设置成端口复用的时候,很容易对一些没有进行单独bind模式的程序造成危害。
比如old的 ping icmp door,简单的sniffer后,收到包,然后设置setoptsock bind web服务,然后建立个cmd进程 bind再80端口。
- 相关文章
- 网络编程之setsockopt
- 浅析:setsockopt()改善程序的健壮性
- [转]浅析:setsockopt()改善socket网络程序的