pelican/examples/reference/src/ChunkerExample.cpp
// Called whenever there is data available on the device.
Called whenever there is data available on the device.
Called whenever there is data available on the device .
void ChunkerExample::next(QIODevice* device)
{
    QUdpSocket* udpSocket = static_cast<QUdpSocket*>(device);
    _bytesRead = 0;
    WritableData writableData = getDataStorage(_chunkSize);
    if (writableData.isValid()) {
        char* ptr = (char*) (writableData.ptr());
        while (isActive() && _bytesRead < _chunkSize) {
            bool ok = udpSocket->hasPendingDatagrams();
            if (!ok) {
                udpSocket->waitForReadyRead(100);
                continue;
            }
            qint64 maxlen = _chunkSize - _bytesRead;
            qint64 length = udpSocket->readDatagram(ptr + _bytesRead, maxlen);
            if (length > 0)
                _bytesRead += length;
        }
    }
    else {
        udpSocket->readDatagram(0, 0);
    }
}
void ChunkerExample :: next ( QIODevice * device ) { QUdpSocket * udpSocket = static_cast < QUdpSocket * > ( device ) ; _bytesRead = 0 ; WritableData writableData = getDataStorage ( _chunkSize ) ; if ( writableData . isValid ( ) ) { char * ptr = ( char * ) ( writableData . ptr ( ) ) ; while ( isActive ( ) && _bytesRead < _chunkSize ) { bool ok = udpSocket -> hasPendingDatagrams ( ) ; if ( ! ok ) { udpSocket -> waitForReadyRead ( 100 ) ; continue ; } qint64 maxlen = _chunkSize - _bytesRead ; qint64 length = udpSocket -> readDatagram ( ptr + _bytesRead , maxlen ) ; if ( length > 0 ) _bytesRead += length ; } } else { udpSocket -> readDatagram ( 0 , 0 ) ; } }
Called whenever there is data available on the device.
Called whenever there is data available on the device .
// Get a pointer to the UDP socket. // Get writable buffer space for the chunk. // 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. // Must discard the datagram if there is no available space.