Example #1
0
void Server::incomingConnection(int socketDescriptor)
{
    qDebug() << "Server: incoming connection";

    QMutexLocker lock(&m_serverPropMutex);
    ServerConnection* connection = new ServerConnection(socketDescriptor, m_lossless, m_maxFramesInQueue, m_maxFramesInFlight);
	connection->setAcknowledgeNeeded(m_acknowledge);
	lock.unlock();

    // let errors go through the error reporting signal of this class
    connect( this, SIGNAL( onError(PlvErrorType,QString)),
             connection, SIGNAL(onError(PlvErrorType,QString)));

    // move the connection to its own thread
    QThreadEx* connectionThread = new QThreadEx();
    connection->moveToThread(connectionThread);

    // when the connection is done it is scheduled for deletion
    connect( connection, SIGNAL(finished()),
             connection, SLOT(deleteLater()));

    // when the connection is done, it stops its thread
    connect( connection, SIGNAL(finished()),
             connectionThread, SLOT(quit()));

    // start the connection when its thread is started
    connect( connectionThread, SIGNAL(started()),
             connection, SLOT(start()));

    // inform server when this serverthead is waiting on the client
    connect( connection, SIGNAL( waitingOnClient(ServerConnection*,bool)),
             this, SLOT( serverThreadStalled(ServerConnection*,bool)) );

    connect( parent(), SIGNAL( maxFramesInQueueChanged(int) ),
             connection, SLOT( setMaxFramesInQueue(int) ) ); //setMaxFrameInQueue &&maxFrameInQueueChanged added in TODO check

    connect( parent(), SIGNAL( maxFramesInFlightChanged(int) ),
             connection, SLOT( setMaxFramesInFlight(int)) );

    connect( parent(), SIGNAL( losslessChanged(bool) ),
             connection, SLOT( setLossless(bool)) );

    // stop this connection when stopAllConnections is called
    connect( this, SIGNAL(stopAllConnections()), connection, SLOT(stop()));

    // start the connection thread and its event loop
    connectionThread->start();

    // connection receives all broadcasts and sends it to its connection
    connect( this, SIGNAL( broadcastFrame(quint32,QByteArray)),
             connection, SLOT( queueFrame(quint32,QByteArray)));
}
Example #2
0
void Server::incomingConnection(int socketDescriptor)
{
    qDebug() << "Server: incoming connection";

    ServerConnection* connection = new ServerConnection(socketDescriptor);

    // let errors go through the error reporting signal of this class
    this->connect( connection,
                   SIGNAL(errorOccurred(PipelineErrorType,QString)),
                   SIGNAL(error(PipelineErrorType,QString)));

    // move the connection to its own thread
    QThreadEx* connectionThread = new QThreadEx();
    connection->moveToThread(connectionThread);

    // when the connection is done it is scheduled for deletion
    connect( connection, SIGNAL(finished()),
             connection, SLOT(deleteLater()));

    // when the connection is done, it stops its thread
    connect( connection, SIGNAL(finished()),
             connectionThread, SLOT(quit()));

    // start the connection when its thread is started
    connect( connectionThread, SIGNAL(started()),
             connection, SLOT(start()));

    // inform server when this serverthead is waiting on the client
    connect( connection, SIGNAL( waitingOnClient(ServerConnection*,bool)),
             this, SLOT( serverThreadStalled(ServerConnection*,bool)) );

    // stop this connection when stopAllConnections is called
    connect( this, SIGNAL(stopAllConnections()), connection, SLOT(stop()));

    // start the connection thread and its event loop
    connectionThread->start();

    // connection receives all broadcasts and sends it to its connection
    connect( this, SIGNAL( broadcastFrame(quint32,QByteArray)),
             connection, SLOT( queueFrame(quint32,QByteArray)));
}
Example #3
0
void Server::sendFrame(quint32 frameNumber, const QVariantList& frameData)
{
    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_0);

    // write the header
    out << (quint32)0; // reserved for number of bytes later
    out << (quint32)PROTO_FRAME;
    out << (quint32)frameNumber;
    out << (quint32)frameData.size();

    // write all data to the stream
    foreach( const QVariant& v, frameData )
    {
        out << v;
    }

    // calculate size of total data and write it as first 4 bytes
    out.device()->seek(0);
    out << (quint32)(block.size() - sizeof(quint32));

    emit broadcastFrame(frameNumber, block);
}
Example #4
0
void Server::sendFrame(quint32 frameNumber, const QByteArray& data)
{
    emit broadcastFrame(frameNumber, data);
}