pelican/server/test/src/TestUdpChunker.cpp
/**
 * @details
 * Gets the next chunk of data from the UDP socket
 */
@details
Gets the next chunk of data from the UDP socket
@details Gets the next chunk of data from the UDP socket
void TestUdpChunker::next(QIODevice* device)
{
#if 0
    using namespace std;
    cout << "TestUdpChunker::next() " << name().toStdString() << endl;
#endif
    QUdpSocket* udpSocket = static_cast<QUdpSocket*>(device);
    _bytesRead = 0;
    WritableData writableData = getDataStorage(_chunkSize);
    if (!writableData.isValid()) {
        cerr << "-- # usable chunks = " << numUsableChunks(_chunkSize) << endl;
        cerr << "-- max size = " << maxBufferSize() << endl;
        cerr << "-- max chunk size = " << maxChunkSize() << endl;
        cerr << "-- allocated = " << allocatedSize() << endl;
        if (!isActive())
            return;
        udpSocket->readDatagram(0, 0);
        return;
    }
     Get pointer to start of writable memory.
    char* ptr = (char*) (writableData.ptr());
     Read datagrams for chunk from the UDP socket.
    while (isActive() && _bytesRead < _chunkSize) {
         Read the datagram, but avoid using pendingDatagramSize().
        bool ok = udpSocket->hasPendingDatagrams();
        if (!ok) {
             MUST WAIT for the next datagram.
            if( ! isActive() ) return;
            udpSocket->waitForReadyRead(100);
            continue;
        }
        qint64 maxlen = _chunkSize - _bytesRead;
        qint64 length = udpSocket->readDatagram(ptr + _bytesRead, maxlen);
        if (length > 0)
            _bytesRead += length;
    }
    ++_chunkCounter;
#if 0
    cout << "TestUdpChunker::next() READ CHUNK! "
            << name().toStdString()
            << " : " << _chunkCounter
            << endl;
#endif
}
void TestUdpChunker :: next ( QIODevice * device ) { #if 0 using namespace std ; cout << " " << name ( ) . toStdString ( ) << endl ; #endif QUdpSocket * udpSocket = static_cast < QUdpSocket * > ( device ) ; _bytesRead = 0 ; WritableData writableData = getDataStorage ( _chunkSize ) ; if ( ! writableData . isValid ( ) ) { if ( ! isActive ( ) ) return ; udpSocket -> readDatagram ( 0 , 0 ) ; return ; } char * ptr = ( char * ) ( writableData . ptr ( ) ) ; while ( isActive ( ) && _bytesRead < _chunkSize ) { bool ok = udpSocket -> hasPendingDatagrams ( ) ; if ( ! ok ) { if ( ! isActive ( ) ) return ; udpSocket -> waitForReadyRead ( 100 ) ; continue ; } qint64 maxlen = _chunkSize - _bytesRead ; qint64 length = udpSocket -> readDatagram ( ptr + _bytesRead , maxlen ) ; if ( length > 0 ) _bytesRead += length ; } ++ _chunkCounter ; #if 0 cout << " " << name ( ) . toStdString ( ) << " " << _chunkCounter << endl ; #endif }
@details
 Gets the next chunk of data from the UDP socket
@details Gets the next chunk of data from the UDP socket
// Get a pointer to the UDP socket. //    cout << "chunk counter = " << _chunkCounter << endl; // Get writable buffer space for the chunk. // Must discard the datagram if its not possible to // obtain a valid chunk to write into. //        cerr << "-- Invalid chunk ...!" << endl; //        std::string active = (isActive() ? "true" : "false"); //        cerr << "-- isActive? " << active << endl; // //        cerr << "-- # usable chunks = " << numUsableChunks(_chunkSize) << endl; //        cerr << "-- max size = " << maxBufferSize() << endl; //        cerr << "-- max chunk size = " << maxChunkSize() << endl; //        cerr << "-- allocated = " << allocatedSize() << endl; // Get pointer to start of writable memory. // Read datagrams for chunk from the UDP socket. // Read the datagram, but avoid using pendingDatagramSize(). // MUST WAIT for the next datagram.