本文整理汇总了C++中HTTPRequest::GetKeepAlive方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPRequest::GetKeepAlive方法的具体用法?C++ HTTPRequest::GetKeepAlive怎么用?C++ HTTPRequest::GetKeepAlive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPRequest
的用法示例。
在下文中一共展示了HTTPRequest::GetKeepAlive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessWork
void HttpWorkerThread::ProcessWork()
{
// VERBOSE( VB_UPNP, QString( "HttpWorkerThread::ProcessWork:Begin( %1 ) socket=%2" )
// .arg( (long)QThread::currentThread() )
// .arg( m_nSocket ));
bool bTimeout = false;
bool bKeepAlive = true;
BufferedSocketDevice *pSocket = NULL;
HTTPRequest *pRequest = NULL;
try
{
if ((pSocket = new BufferedSocketDevice( m_nSocket )) == NULL)
{
VERBOSE( VB_IMPORTANT, QString( "HttpWorkerThread::ProcessWork - Error Creating BufferedSocketDevice" ));
return;
}
pSocket->SocketDevice()->setBlocking( true );
while( !m_bTermRequested && bKeepAlive && pSocket->IsValid())
{
bTimeout = 0;
int64_t nBytes = pSocket->WaitForMore(m_nSocketTimeout, &bTimeout);
if ( nBytes > 0)
{
// ----------------------------------------------------------
// See if this is a valid request
// ----------------------------------------------------------
if ((pRequest = new BufferedSocketDeviceRequest( pSocket )) != NULL)
{
if ( pRequest->ParseRequest() )
{
bKeepAlive = pRequest->GetKeepAlive();
// ------------------------------------------------------
// Request Parsed... Pass on to Main HttpServer class to
// delegate processing to HttpServerExtensions.
// ------------------------------------------------------
m_pHttpServer->DelegateRequest( this, pRequest );
}
else
{
VERBOSE( VB_UPNP, QString( "HttpWorkerThread::ProcessWork - ParseRequest Failed." ));
pRequest->m_nResponseStatus = 501;
bKeepAlive = false;
}
/*
// Dump Request Header
if (!bKeepAlive )
{
for ( QStringMap::iterator it = pRequest->m_mapHeaders.begin();
it != pRequest->m_mapHeaders.end();
++it )
{
cout << it.key() << ": " << it.data() << endl;
}
}
*/
// ----------------------------------------------------------
// Always MUST send a response.
// ----------------------------------------------------------
if (pRequest->SendResponse() < 0)
{
bKeepAlive = false;
VERBOSE( VB_UPNP, QString( "HttpWorkerThread::ProcessWork socket(%1) - Error returned from SendResponse... Closing connection" )
.arg( m_nSocket ));
}
// ----------------------------------------------------------
// Check to see if a PostProcess was registered
// ----------------------------------------------------------
if ( pRequest->m_pPostProcess != NULL )
pRequest->m_pPostProcess->ExecutePostProcess();
delete pRequest;
pRequest = NULL;
}
else
{
VERBOSE( VB_IMPORTANT, QString( "HttpWorkerThread::ProcessWork - Error Creating BufferedSocketDeviceRequest" ));
bKeepAlive = false;
}
}
else
{
bKeepAlive = false;
}
//.........这里部分代码省略.........
示例2: run
void HttpWorker::run(void)
{
#if 0
LOG(VB_UPNP, LOG_DEBUG,
QString("HttpWorker::run() socket=%1 -- begin").arg(m_socket));
#endif
bool bTimeout = false;
bool bKeepAlive = true;
BufferedSocketDevice *pSocket = NULL;
HTTPRequest *pRequest = NULL;
try
{
if ((pSocket = new BufferedSocketDevice( m_socket )) == NULL)
{
LOG(VB_GENERAL, LOG_ERR, "Error Creating BufferedSocketDevice");
return;
}
pSocket->SocketDevice()->setBlocking( true );
while (m_httpServer.IsRunning() && bKeepAlive && pSocket->IsValid())
{
bTimeout = false;
int64_t nBytes = pSocket->WaitForMore(m_socketTimeout, &bTimeout);
if (!m_httpServer.IsRunning())
break;
if ( nBytes > 0)
{
// ----------------------------------------------------------
// See if this is a valid request
// ----------------------------------------------------------
pRequest = new BufferedSocketDeviceRequest( pSocket );
if (pRequest != NULL)
{
if ( pRequest->ParseRequest() )
{
bKeepAlive = pRequest->GetKeepAlive();
// ------------------------------------------------------
// Request Parsed... Pass on to Main HttpServer class to
// delegate processing to HttpServerExtensions.
// ------------------------------------------------------
if (pRequest->m_nResponseStatus != 401)
m_httpServer.DelegateRequest(pRequest);
}
else
{
LOG(VB_UPNP, LOG_ERR, "ParseRequest Failed.");
pRequest->m_nResponseStatus = 501;
bKeepAlive = false;
}
#if 0
// Dump Request Header
if (!bKeepAlive )
{
for ( QStringMap::iterator it = pRequest->m_mapHeaders.begin();
it != pRequest->m_mapHeaders.end();
++it )
{
LOG(VB_GENERAL, LOG_DEBUG, QString("%1: %2")
.arg(it.key()) .arg(it.data()));
}
}
#endif
// -------------------------------------------------------
// Always MUST send a response.
// -------------------------------------------------------
if (pRequest->SendResponse() < 0)
{
bKeepAlive = false;
LOG(VB_UPNP, LOG_ERR,
QString("socket(%1) - Error returned from "
"SendResponse... Closing connection")
.arg(m_socket));
}
// -------------------------------------------------------
// Check to see if a PostProcess was registered
// -------------------------------------------------------
if ( pRequest->m_pPostProcess != NULL )
pRequest->m_pPostProcess->ExecutePostProcess();
delete pRequest;
pRequest = NULL;
}
else
{
LOG(VB_GENERAL, LOG_ERR,
"Error Creating BufferedSocketDeviceRequest");
//.........这里部分代码省略.........