本文整理汇总了C++中TcpSocket::setTotalBytes方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::setTotalBytes方法的具体用法?C++ TcpSocket::setTotalBytes怎么用?C++ TcpSocket::setTotalBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::setTotalBytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readClient
void Worker::readClient()
{
//if (disabled)
// return;
// This slot is called when the client sent data to the server. The
// server looks if it was a get request and sends a very simple HTML
// document back.
TcpSocket* socket = static_cast<TcpSocket*>(sender());
if(socket->bytesAvailable())
{
if ( socket->isNewSocket())
{
QByteArray incomingContent=socket->readAll();
http_parser_settings settings;
settings. on_message_begin=onMessageBegin;
settings. on_url=onUrl;
settings. on_header_field=onHeaderField;
settings. on_header_value=onHeaderValue;
settings. on_headers_complete=onHeadersComplete;
settings. on_body=onBody;
settings. on_message_complete=onMessageComplete;
http_parser_init(&m_parser,HTTP_REQUEST);
m_parser.data = socket;
size_t nparsed = http_parser_execute(&m_parser,&settings,incomingContent.constData(),incomingContent.count());
if(m_parser.upgrade)
{
qDebug()<<"upgrade";
}
else if(nparsed != static_cast<size_t>(incomingContent.count()))
{
qDebug()<<"nparsed:"<<nparsed<<"buffer size:"<<incomingContent.count();
}
else
{
//qDebug()<<"parsing seems to be succeed!";
}
socket->setRawHeader(incomingContent);
bool isBodySizeOK=false;
unsigned int bodySize = 0;
QSharedPointer<QString> contentLength = socket->getHeader().getHeaderInfo("Content-Length");
if (!contentLength.isNull())
{
bodySize = contentLength->toUInt(&isBodySizeOK);
if(isBodySizeOK==false)
{
bodySize=0;
}
}
socket->setTotalBytes(bodySize);
socket->notNew();
}
else
{
qDebug()<<"socket size:"<<socket->getTotalBytes()<<"current Size:"<<socket->getBytesHaveRead();
QByteArray incomingContent=socket->readAll();
socket->appendData(incomingContent);
}
if (socket->getBytesHaveRead() > (16*1024*1024))
{
socket->getResponse().setStatusCode(400);
socket->getResponse() << "maximum message size above 16mb.";
socket->getResponse().finish();
socket->waitForBytesWritten();
socket->close();
}
else
if(socket->isEof())
{
PathTreeNode::HttpVerb handlerType;
if(m_parser.method==HTTP_GET)
{
socket->getHeader().setHttpMethod(HttpHeader::HttpMethod::HTTP_GET);
handlerType=PathTreeNode::GET;
}
else if(m_parser.method==HTTP_POST)
{
socket->getHeader().setHttpMethod(HttpHeader::HttpMethod::HTTP_POST);
handlerType=PathTreeNode::POST;
}
else
{
qDebug()<<"not get and post"<<socket->atEnd()<<socket->bytesAvailable()<<socket->ConnectedState;
socket->close();
return;
//.........这里部分代码省略.........