Skip to content

Commit

Permalink
Fixes to detecting jingle-ft stream finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Apr 22, 2024
1 parent 0831952 commit 1f22b3e
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/xmpp/xmpp-im/jingle-ft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace XMPP { namespace Jingle { namespace FileTransfer {
}
}

inline qint64 getBlockSize()
inline std::size_t getBlockSize()
{
auto sz = qint64(connection->blockSize());
return sz ? sz : 8192;
Expand All @@ -266,13 +266,13 @@ namespace XMPP { namespace Jingle { namespace FileTransfer {
expectReceived();
return; // everything is written
}
auto sz = getBlockSize();
quint64 sz = getBlockSize();
if (bytesLeft && sz > *bytesLeft) {
sz = *bytesLeft;
}
QByteArray data;
if (device->isSequential()) {
sz = qMin(sz, device->bytesAvailable());
sz = qMin(sz, quint64(device->bytesAvailable()));
if (!sz)
return; // we will come back on readyRead
}
Expand Down Expand Up @@ -329,7 +329,7 @@ namespace XMPP { namespace Jingle { namespace FileTransfer {
if (connection->features() & TransportFeature::MessageOriented) {
data = connection->readDatagram().data();
} else {
qint64 sz = 65536; // shall we respect transport->blockSize() ?
quint64 sz = 65536; // shall we respect transport->blockSize() ?
if (bytesLeft && sz > *bytesLeft) {
sz = *bytesLeft;
}
Expand Down Expand Up @@ -372,6 +372,14 @@ namespace XMPP { namespace Jingle { namespace FileTransfer {
lastReason = Reason();
lastError.reset();

if (acceptFile.range().isValid()) {
if (acceptFile.range().length) {
bytesLeft = acceptFile.range().length;
}
} else {
bytesLeft = acceptFile.size();
}

if (streamingMode) {
qDebug("jingle-ft: streaming mode is active for %s",
qUtf8Printable(q->pad()->session()->peer().full()));
Expand Down Expand Up @@ -427,21 +435,16 @@ namespace XMPP { namespace Jingle { namespace FileTransfer {

setState(State::Active);
if (acceptFile.range().isValid()) {
if (acceptFile.range().length) {
bytesLeft = acceptFile.range().length;
}
emit q->deviceRequested(acceptFile.range().offset, bytesLeft);
} else {
bytesLeft = acceptFile.size();
emit q->deviceRequested(0, bytesLeft);
}
}

void tryFinalizeIncoming()
{
if (q->_state == State::Finished || outgoingReceived || streamingMode)
return;
if (connection->isOpen() && (!bytesLeft || *bytesLeft > 0))
auto moreBytesExpected = bytesLeft && *bytesLeft > 0;
if (q->_state == State::Finished || outgoingReceived || (connection->isOpen() && moreBytesExpected))
return;

// data read finished. check other stuff
Expand Down Expand Up @@ -659,8 +662,10 @@ namespace XMPP { namespace Jingle { namespace FileTransfer {
if (d->outgoingReceived) {
d->outgoingReceived = false;
Received received(creator(), _contentName);
return OutgoingUpdate { QList<QDomElement>() << received.toXml(doc),
[this](bool) { d->setState(State::Finished); } };
return OutgoingUpdate { QList<QDomElement>() << received.toXml(doc), [this](bool) {
d->lastReason = Reason(Reason::Condition::Success);
d->setState(State::Finished);
} };
}
if (!d->outgoingChecksum.isEmpty()) {
ContentBase cb(_pad->session()->role(), _contentName);
Expand Down Expand Up @@ -718,6 +723,7 @@ namespace XMPP { namespace Jingle { namespace FileTransfer {

if (_creator == _pad->session()->role() && _state <= State::ApprovedToSend) {
// local content, not yet sent to remote
d->lastReason = _terminationReason;
setState(State::Finished);
return;
}
Expand Down

0 comments on commit 1f22b3e

Please sign in to comment.