Exemplo n.º 1
0
ApiLocalConnectionHandler::ApiLocalConnectionHandler(
        ApiServer* apiServer, QLocalSocket* sock, QObject *parent) :
    QObject(parent), mApiServer(apiServer), mLocalSocket(sock),
    mState(WAITING_PATH)
{
	connect(mLocalSocket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
	connect(sock, SIGNAL(readyRead()), this, SLOT(handlePendingRequests()));
}
Exemplo n.º 2
0
void
AsyncLoop::asyncLoop()
{
    // This runs as an asynchronous task.

    dbgAssert( m_multiCurl );

    SocketActions socketActions;

    while( !m_shutdown )
    {
        try
        {
            if( m_hasPending )
            {
                // Add new and remove canceled requests.

                handlePendingRequests();
                dbgAssert( m_runningRequestCount >= m_socketPool.size() );
            }

            size_t socketCount =  m_socketPool.size();

            if( m_runningRequestCount > socketCount )
            {
                // We have added more requests to the multi-handle than the number of sockets
                // curl reported back to us yet. Execute 'timeout' action.

                executeSocketAction( INVALID_SOCKET_HANDLE );
            }
            else
            {
                // Wait for any activity.

                socketActions.reserve( socketCount );

                if( m_socketPool.wait( m_socketActionTimeout, c_interruptOnlyTimeout, &socketActions ) )
                {
                    // Some activity (or interrupt) has been detected, handle it.

                    for( SocketActions::const_iterator it = socketActions.begin();
                        it != socketActions.end(); ++it )
                    {
                        executeSocketAction( it->first, it->second );
                    }
                }
                else
                {
                    // No activity, go through all sockets and check their status.
                    // Note: curl_multi_socket_all(..) is deprecated but it doesn't seem
                    // there is another way to check all sockets. Without this call some sockets
                    // may stuck for very long.

                    int stillRunning = 0;
                    CURLMcode multiCurlCode = curl_multi_socket_all( m_multiCurl, &stillRunning );
                    raiseIfError( multiCurlCode );
                }
            }

            // Remove completed requests.

            removeCompletedRequests();
            dbgAssert( m_runningRequestCount >= m_socketPool.size() );
        }
        catch( ... )
        {
            // Continue to work no matter what.

            handleBackgroundError();
            taskSleep( 3000 );
        }
    }
}