15
15
16
16
#include < algorithm>
17
17
#include < memory>
18
- #include < thread>
19
18
20
19
QT_BEGIN_NAMESPACE
21
20
@@ -44,7 +43,6 @@ QHttp2Stream::QHttp2Stream(QHttp2Connection *connection, quint32 streamID) noexc
44
43
}
45
44
46
45
QHttp2Stream::~QHttp2Stream () noexcept {
47
- printf (" ~QHttp2Stream\n " );
48
46
if (auto *connection = getConnection ()) {
49
47
if (m_state == State::Open || m_state == State::HalfClosedRemote) {
50
48
qCDebug (qHttp2ConnectionLog, " [%p] stream %u, destroyed while still open" , connection,
@@ -292,7 +290,6 @@ bool QHttp2Stream::sendDATA(const QByteArray &payload, bool endStream)
292
290
auto *byteDevice = QNonContiguousByteDeviceFactory::create (payload);
293
291
m_owningByteDevice = true ;
294
292
byteDevice->setParent (this );
295
- printf (" QHttp2Stream::sendDATA, byteDevice = %p\n " , (void *)byteDevice);
296
293
return sendDATA (byteDevice, endStream);
297
294
}
298
295
@@ -313,7 +310,6 @@ bool QHttp2Stream::sendDATA(const QByteArray &payload, bool endStream)
313
310
*/
314
311
bool QHttp2Stream::sendDATA (QIODevice *device, bool endStream)
315
312
{
316
- printf (" QHttp2Stream::sendDATA(QIODevice *%p, bool %d)\n " , (void *)device, endStream);
317
313
Q_ASSERT (!m_uploadDevice);
318
314
Q_ASSERT (!m_uploadByteDevice);
319
315
Q_ASSERT (device);
@@ -330,7 +326,6 @@ bool QHttp2Stream::sendDATA(QIODevice *device, bool endStream)
330
326
m_owningByteDevice = true ;
331
327
byteDevice->setParent (this );
332
328
m_uploadDevice = device;
333
- printf (" QHttp2Stream::sendDATA, m_uploadDevice = %p, byteDevice = %p\n " , (void *)device, (void *)byteDevice);
334
329
return sendDATA (byteDevice, endStream);
335
330
}
336
331
@@ -351,7 +346,6 @@ bool QHttp2Stream::sendDATA(QIODevice *device, bool endStream)
351
346
*/
352
347
bool QHttp2Stream::sendDATA (QNonContiguousByteDevice *device, bool endStream)
353
348
{
354
- printf (" QHttp2Stream::sendDATA(QNonContiguousByteDevice *%p, bool %d)\n " , (void *)device, endStream);
355
349
Q_ASSERT (!m_uploadByteDevice);
356
350
Q_ASSERT (device);
357
351
if (m_state != State::Open && m_state != State::HalfClosedRemote) {
@@ -365,11 +359,8 @@ bool QHttp2Stream::sendDATA(QNonContiguousByteDevice *device, bool endStream)
365
359
getConnection (), m_streamID, device);
366
360
m_uploadByteDevice = device;
367
361
m_endStreamAfterDATA = endStream;
368
- printf (" QHttp2Stream::sendDATA, m_uploadByteDevice = %p\n " , (void *)device);
369
362
connect (m_uploadByteDevice, &QNonContiguousByteDevice::readyRead, this ,
370
363
&QHttp2Stream::maybeResumeUpload);
371
- auto functor = [p=m_uploadByteDevice](QObject*o){printf (" m_uploadByteDevice %p destroyed %p\n " ,(void *)p, (void *)o);};
372
- QObject::connect (m_uploadByteDevice, &QObject::destroyed, m_uploadByteDevice, functor);
373
364
connect (m_uploadByteDevice, &QObject::destroyed, this , &QHttp2Stream::uploadDeviceDestroyed);
374
365
375
366
internalSendDATA ();
@@ -405,22 +396,17 @@ void QHttp2Stream::internalSendDATA()
405
396
};
406
397
407
398
bool sentEND_STREAM = false ;
408
- bool enteredFirstWhile = false ;
409
- bool enteredSecondWhile = false ;
410
399
while (remainingWindowSize && deviceCanRead ()) {
411
- enteredFirstWhile = true ;
412
400
quint32 bytesWritten = 0 ;
413
401
qint32 remainingBytesInFrame = qint32 (connection->maxFrameSize );
414
402
frameWriter.start (FrameType::DATA, FrameFlag::EMPTY, streamID ());
415
403
416
404
while (remainingWindowSize && deviceCanRead () && remainingBytesInFrame) {
417
- enteredSecondWhile = true ;
418
405
const qint32 maxToWrite = std::min (remainingWindowSize, remainingBytesInFrame);
419
406
420
407
qint64 outBytesAvail = 0 ;
421
408
const char *readPointer = m_uploadByteDevice->readPointer (maxToWrite, outBytesAvail);
422
409
if (!readPointer || outBytesAvail <= 0 ) {
423
- printf (" not writing, readPointer: %s, outBytesAvail: %d\n " , readPointer?" notnull" :" null" , (int )outBytesAvail);
424
410
qCDebug (qHttp2ConnectionLog,
425
411
" [%p] stream %u, cannot write data, device (%p) has %lld bytes available" ,
426
412
connection, m_streamID, m_uploadByteDevice, outBytesAvail);
@@ -431,7 +417,6 @@ void QHttp2Stream::internalSendDATA()
431
417
m_uploadByteDevice->advanceReadPointer (bytesToWrite);
432
418
433
419
bytesWritten += bytesToWrite;
434
- printf (" bytesWritten: %d\n " , (int )bytesWritten);
435
420
436
421
m_sendWindow -= bytesToWrite;
437
422
Q_ASSERT (m_sendWindow >= 0 );
@@ -450,47 +435,26 @@ void QHttp2Stream::internalSendDATA()
450
435
frameWriter.addFlag (FrameFlag::END_STREAM);
451
436
}
452
437
if (!frameWriter.write (*socket)) {
453
- printf (" failed to write to socket\n " );
454
438
qCDebug (qHttp2ConnectionLog, " [%p] stream %u, failed to write to socket" , connection,
455
439
m_streamID);
456
440
return finishWithError (INTERNAL_ERROR, " failed to write to socket" _L1);
457
441
}
458
442
459
443
totalBytesWritten += bytesWritten;
460
444
}
461
- if (!enteredFirstWhile){
462
- printf (" Did not enter first while, remainingWindowSize: %d, deviceCanRead(): %d\n " , (int )remainingWindowSize, deviceCanRead ());
463
- } else if (!enteredSecondWhile) {
464
- printf (" Did not enter second while, remainingWindowSize: %d, deviceCanRead(): %d, remainingBytesInFrame: %d\n " , (int )remainingWindowSize, deviceCanRead (), int (connection->maxFrameSize ));
465
- }
466
445
467
446
qCDebug (qHttp2ConnectionLog,
468
447
" [%p] stream %u, wrote %lld bytes total, if the device is not exhausted, we'll write "
469
448
" more later. Remaining window size: %d" ,
470
449
connection, m_streamID, totalBytesWritten, remainingWindowSize);
471
450
472
- printf (" emit totalBytesWritten(%d)\n " , (int )totalBytesWritten);
473
451
emit bytesWritten (totalBytesWritten);
474
- printf (" sentEND_STREAM: %d\n " , sentEND_STREAM);
475
- bool dcr;
476
- bool ae;
477
- if (!sentEND_STREAM) {
478
- dcr = deviceCanRead ();
479
- printf (" deviceCanRead(): %d\n " , dcr);
480
- if (!dcr) {
481
- ae = m_uploadByteDevice->atEnd ();
482
- printf (" m_uploadByteDevice->atEnd(): %d\n " , ae);
483
- }
484
- }
485
- if (sentEND_STREAM || (!dcr && ae)) {
486
- // qDebug(qHttp2ConnectionLog,
487
- // "[%p] stream %u, exhausted device %p, sent END_STREAM? %d, %ssending end stream "
488
- // "after DATA",
489
- // connection, m_streamID, m_uploadByteDevice, sentEND_STREAM,
490
- // m_endStreamAfterDATA ? "" : "not ");
491
- if (!sentEND_STREAM) {
492
- printf (" m_endStreamAfterDATA: %d\n " , m_endStreamAfterDATA);
493
- }
452
+ if (sentEND_STREAM || (!deviceCanRead () && m_uploadByteDevice->atEnd ())) {
453
+ qCDebug (qHttp2ConnectionLog,
454
+ " [%p] stream %u, exhausted device %p, sent END_STREAM? %d, %ssending end stream "
455
+ " after DATA" ,
456
+ connection, m_streamID, m_uploadByteDevice, sentEND_STREAM,
457
+ m_endStreamAfterDATA ? " " : " not " );
494
458
if (!sentEND_STREAM && m_endStreamAfterDATA) {
495
459
// We need to send an empty DATA frame with END_STREAM since we
496
460
// have exhausted the device, but we haven't sent END_STREAM yet.
@@ -501,17 +465,13 @@ void QHttp2Stream::internalSendDATA()
501
465
}
502
466
finishSendDATA ();
503
467
} else if (isUploadBlocked ()) {
504
- printf (" Upload is blocked\n " );
505
- // qDebug(qHttp2ConnectionLog, "[%p] stream %u, upload blocked", connection, m_streamID);
468
+ qCDebug (qHttp2ConnectionLog, " [%p] stream %u, upload blocked" , connection, m_streamID);
506
469
emit uploadBlocked ();
507
- } else {
508
- printf (" Upload is not blocked\n " );
509
470
}
510
471
}
511
472
512
473
void QHttp2Stream::finishSendDATA ()
513
474
{
514
- printf (" QHttp2Stream::finishSendDATA()\n " );
515
475
if (m_endStreamAfterDATA)
516
476
transitionState (StateTransition::CloseLocal);
517
477
@@ -633,9 +593,7 @@ void QHttp2Stream::sendWINDOW_UPDATE(quint32 delta)
633
593
634
594
void QHttp2Stream::uploadDeviceDestroyed ()
635
595
{
636
- printf (" uploadDeviceDestroyed\n " );
637
596
if (isUploadingDATA ()) {
638
- printf (" isUploadingDATA is true\n " );
639
597
// We're in the middle of sending DATA frames, we need to abort
640
598
// the stream.
641
599
streamError (CANCEL, QLatin1String (" Upload device destroyed while uploading" ));
@@ -736,7 +694,6 @@ void QHttp2Stream::handleDATA(const Frame &inboundFrame)
736
694
inboundFrame.dataSize ());
737
695
if (endStream)
738
696
transitionState (StateTransition::CloseRemote);
739
- printf (" dataReceived: `%s` endStream: %d\n " , fragment.toStdString ().c_str (), endStream);
740
697
emit dataReceived (fragment, endStream);
741
698
m_downloadBuffer.append (std::move (fragment));
742
699
}
@@ -755,12 +712,6 @@ void QHttp2Stream::handleHEADERS(Http2::FrameFlags frameFlags, const HPack::Http
755
712
if (endStream)
756
713
transitionState (StateTransition::CloseRemote);
757
714
if (!headers.empty ()) {
758
- for (auto &h:headers){
759
- if ( h.name .toStdString () == " :status" ){
760
- printf (" header ':status' %s received\n " , h.value .toStdString ().c_str ());
761
- break ;
762
- }
763
- }
764
715
m_headers.insert (m_headers.end (), headers.begin (), headers.end ());
765
716
emit headersUpdated ();
766
717
}
0 commit comments