本文整理汇总了C++中TCPSocket::readSocket方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPSocket::readSocket方法的具体用法?C++ TCPSocket::readSocket怎么用?C++ TCPSocket::readSocket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPSocket
的用法示例。
在下文中一共展示了TCPSocket::readSocket方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
int BufferManager::read(TCPSocket &sock)
{
int ret;
//while(true)
{
if(m_bInit)
{
m_InReq.ioBuf = NULL;
memset(&m_InReq.m_msgHeader,0,HEADER_SIZE);
m_iLen = HEADER_SIZE;
m_bInit = false;
}
if(m_bReadHead)
{
if((ret = sock.readSocket(((char *)(&m_InReq.m_msgHeader)) + m_iOffset,HEADER_SIZE - m_iOffset)) < 0)
{
if(!((errno == EWOULDBLOCK)) || (errno == EINTR))
{
handleSyscallError("BufferManager::read()");
return FAILED;
}
return SUCCESSFUL;
}
else if(ret == 0)
{
return FAILED;
}
m_iOffset += (unsigned int)ret;
if(m_iOffset == HEADER_SIZE)
{
m_iOffset = 0;
m_iLen = m_InReq.m_msgHeader.length;
if(m_iLen > 0)
{
m_InReq.ioBuf = new char[m_iLen + 1];
memset(m_InReq.ioBuf,0,m_iLen + 1);
m_bReadHead = false;
} else if(m_iLen == 0)
{
m_InReq.ioBuf = NULL;
if(m_pAgent)
{
m_pAgent->readBack(m_InReq);
this->m_bInit = true;
}
this->m_bReadHead = true;
return SUCCESSFUL;
} else {
m_bReadHead = true;
handleError("the data length is illegal.");
return FAILED;
}
}
} else {
if((ret = sock.readSocket(m_InReq.ioBuf + m_iOffset,m_iLen - m_iOffset)) < 0)
{
if(!((errno == EWOULDBLOCK) || (errno == EINTR)))
{
handleSyscallError("BufferManger::readSocket");
return FAILED;
}
} else if(ret == 0)
{
handleSyscallError("the peer close the connection");
return FAILED;
}
m_iOffset += (unsigned int)ret;
if(m_iOffset == m_iLen)
{
m_InReq.ioBuf[m_iLen] = '\0';
m_iOffset = 0;
m_iLen = 0;
m_bReadHead = true;
if(m_pAgent)
{
#ifdef DEBUG
std::cout << "pAgent:"<<typeid(m_pAgent).name()\
<<",addr:"<<m_pAgent<<std::endl;
#endif
m_pAgent->readBack(m_InReq);
this->m_bInit = true;
}
if(m_InReq.ioBuf)
{
delete []m_InReq.ioBuf;
m_InReq.ioBuf = NULL;
}
return SUCCESSFUL;
}
}
return (int)(m_iLen - m_iOffset);
}
}
示例2: read
int BufferManager::read(TCPSocket &sock)
{
int ret;
if (m_bInit) {
m_InReq.ioBuf = NULL;
memset(&m_InReq.m_msgHeader, 0, HEADER_SIZE);
m_bInit = false;
m_iLen = HEADER_SIZE;
}
if (m_bReadHead) {
if ((ret = sock.readSocket(((char *)(&(m_InReq.m_msgHeader))) + m_iOffset, \
HEADER_SIZE - m_iOffset)) < 0) {
if (!((errno == EWOULDBLOCK) || (errno == EINTR))) {
DEV_LOG(LERROR, OUT_BOTH, "BufferManager::read()");
return FAILED;
}
return SUCCESSFUL;
} else if (ret == 0) {
DEV_LOG(LERROR, OUT_BOTH, "the opposit close the connection");
return FAILED;
}
m_iOffset += (unsigned int)ret;
if (m_iOffset == HEADER_SIZE) {
m_iOffset = 0;
m_iLen = m_InReq.m_msgHeader.length;
if (m_iLen > 0) {
m_InReq.ioBuf = new char[m_iLen + 1];
m_bReadHead = false;
} else if (m_iLen == 0) {
if (m_Agent != NULL) {
m_Agent->readBack(m_InReq);
this->m_bInit = true;
}
this->m_bReadHead = true;
return SUCCESSFUL;
} else {
m_bReadHead = true;
DEV_LOG(LERROR, OUT_BOTH, "the data length is not illegal");
return FAILED;
}
}
}
if (!m_bReadHead) {
if ((ret = sock.readSocket(m_InReq.ioBuf + m_iOffset, \
m_iLen - m_iOffset)) < 0) {
if (!((errno == EWOULDBLOCK) || (errno == EINTR))) {
DEV_LOG(LERROR, OUT_BOTH, "readSocket in BufferMananger");
return FAILED;
}
return SUCCESSFUL;
} else if (ret == 0) {
DEV_LOG(LERROR, OUT_BOTH, "the opposit close the connection in readData");
return FAILED;
}
m_iOffset += (unsigned int)ret;
if (m_iOffset == m_iLen) {
m_InReq.ioBuf[m_iLen] = 0;
m_iOffset = 0;
m_iLen = 0;
this->m_bReadHead = true;
if (m_Agent != NULL) {
m_Agent->readBack(m_InReq);
this->m_bInit = true;
}
if (m_InReq.ioBuf != NULL) {
delete [] m_InReq.ioBuf;
m_InReq.ioBuf = NULL;
}
return SUCCESSFUL;
}
}
return (int)(m_iLen - m_iOffset);
}