Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QHttpResponse::allBytesWritten stops emiting when writing #38

Open
demiantres opened this issue May 8, 2017 · 1 comment
Open

QHttpResponse::allBytesWritten stops emiting when writing #38

demiantres opened this issue May 8, 2017 · 1 comment

Comments

@demiantres
Copy link

The "QHttpResponse::allBytesWritten" signal is emited only a few times when manually writing data to the client. This leads to incomplete downloads.

`req->onEnd(this, req, res {

QFile* f = new QFile(filename); // a file of some MB size
if (f->open(QFile::ReadOnly))
{
	res->addHeader("content-length", QString::number(f->size()).toLatin1());
	res->addHeader("content-type", "application/octet-stream");
	res->addHeader("content-disposition", QStringLiteral("attachment; filename=\"%1\"").arg(info.fileName()).toLatin1());
	//res->addHeader("connection", "Keep-Alive");
	//res->addHeader("keep-alive", "timeout=600, max=100");
	res->setStatusCode(qhttp::ESTATUS_OK);
	connect(res, &QHttpResponse::allBytesWritten, this, [this, f, res] {
		qDebug() << "Write more... " << f->pos(); // called only a few times
		QByteArray data = f->read(50000);
		if (data.length() == 0)
		{
			qDebug() << "END"; // never called
			res->end();
			f->close();
			f->deleteLater();
		}
		else
		{
			res->write(data); // called a few times
		}
	});

	QByteArray data = f->read(50000);
	if (data.length() > 0)
	{
		res->write(data);
		return;
	}
	else
	{
		f->close();
	}
}
f->deleteLater();

});`

@demiantres
Copy link
Author

demiantres commented May 8, 2017

Got it. Is a Qt Windows bug related to the QTCPSocker signal.

EDIT The problem also happens with other systems (e.g. iOS).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant