- 论坛徽章:
- 0
|
int testReceive()
{
unsigned int m_size=16;//m_size为m_buff大小,2的N次方,为什么要这样定义呢
unsigned int m_write=5;//已经往m_buff写的字节数? //表示接收字节数?
unsigned int m_read=1;//表示读m_buff的字节数? //表示发送字节数?
assert(is_power_of_2(m_size));
unsigned int len = m_size - m_write + m_read; // len is free space
if (len < MIN_SPACE_SIZE)
return ET_BUFF_FULL;
unsigned int offset=m_write & (m_size -1);//offset不是等于m_write吗,这样写是不是多余了?
unsigned int b=m_size - (m_write & (m_size -1));
unsigned int len2 = min(len,b);//这个是不是也多余了,因为b= m_size - m_write ,而len = m_size - m_write + m_read
//int bytes = stream.ReceiveNB(m_buff + (m_write & (m_size - 1)), len2);
assert(len2 != 0);
return len2;
}
inline bool is_power_of_2(unsigned int x)//2的N次方,为什么要这样定义呢
{
return (x != 0) && ((x & (x - 1)) == 0);
}
#define min(a,b) (((a) < (b)) ? (a) : (b)) |
|