pelican/examples/example-2/server/StreamChunker.cpp
/*
 * Function that returns an IO device from which input data can be read.
 *
 * In order for the chunker (and therefore data server) to stay alive between
 * injection of data from invocations of the emulator binary used in this
 * example the chunker here creates a TCPServer and returns a connected
 * TCP socket whenever that becomes available upon connection with the emulator.
 *
 * The function blocks until a connection can be made.
 *
 * Each time the TCP socket disconnects, for example because the emulator has
 * finished, the DataReciever will attempt to reconnect by calling this method
 * again.
 *
 * TODO add a configurable timeout when waiting for new connections.
 */
Function that returns an IO device from which input data can be read.
In order for the chunker (and therefore data server) to stay alive between
injection of data from invocations of the emulator binary used in this
example the chunker here creates a TCPServer and returns a connected
TCP socket whenever that becomes available upon connection with the emulator.

The function blocks until a connection can be made.

Each time the TCP socket disconnects, for example because the emulator has
finished, the DataReciever will attempt to reconnect by calling this method
again.


Function that returns an IO device from which input data can be read . In order for the chunker ( and therefore data server ) to stay alive between injection of data from invocations of the emulator binary used in this example the chunker here creates a TCPServer and returns a connected TCP socket whenever that becomes available upon connection with the emulator . The function blocks until a connection can be made . Each time the TCP socket disconnects for example because the emulator has finished the DataReciever will attempt to reconnect by calling this method again .
QIODevice* StreamChunker::newDevice()
{
    if (tcpServer_ == 0) {
        tcpServer_ = new QTcpServer();
        cout << endl;
        cout << "StreamChunker: Created a QTcpServer listening on:" << endl;
        cout << " * host = " << host().toStdString() << endl;
        cout << " * port = " << port() << endl;
        tcpServer_->listen(QHostAddress(host()), port());
    }
    cout << " * Waiting for a connection... " << flush;
    tcpServer_->waitForNewConnection(-1);
    cout << " Connected!" << endl << endl;
    timer_.start();
    return tcpServer_->nextPendingConnection();
}
QIODevice * StreamChunker :: newDevice ( ) { if ( tcpServer_ == 0 ) { tcpServer_ = new QTcpServer ( ) ; cout << endl ; cout << " " << endl ; cout << " " << host ( ) . toStdString ( ) << endl ; cout << " " << port ( ) << endl ; tcpServer_ -> listen ( QHostAddress ( host ( ) ) , port ( ) ) ; } cout << " " << flush ; tcpServer_ -> waitForNewConnection ( -1 ) ; cout << " " << endl << endl ; timer_ . start ( ) ; return tcpServer_ -> nextPendingConnection ( ) ; }
Function that returns an IO device from which input data can be read.
Function that returns an IO device from which input data can be read .
// Note: // The server has to be created here (in the newDevice() function) // so that it is created in the DataReciever thread managing this chunker. // As this function is also used to reconnect, it needs to make sure the // QTcpServer is not allocated and set up twice.