QIODevice::write (QTcpSocket): device not open
Unsolved
General and Desktop
-
Hi
I'm using qhttpengine in my server application to provide some API for React based website. I know it is old and I should switch to eg. Cutelyst
After I have switched to SSL with this API I have a problem:
When serwer is sending more data (like a 41kb PDF file encoded to Base64) QTcpSocket is being closed during transmission before I send the data, I can see in logs:Warning: 2021-09-09 10:39:06 QIODevice::write (QTcpSocket): device not open Debug: 2021-09-09 10:39:06 HttpServer::addHeadersAndWrite data.size 56843
and user receives:
Error: Transferred a partial file
Without SSL, no problem.
Where to look ? Is there some buffer size or something?
I'm also using QSslSocket in other application and if I set dataSize variable to quint64, I can send big files.Best Regards
Marek -
Hi,
How have your switched to ssl ?
-
@SGaist Hi
By setting certificate in init function
void HttpServer::init() { const char *post_method="POST"; const char *put_method="PUT"; const char *options_method="OPTIONS"; handler.registerMethod(this->getEndpointString(EndpointGetClients), [](QHttpEngine::Socket *socket) { HttpServer *p=static_cast<HttpServer*>(Vr().httpServer); p->processConnection(socket,QHttpEngine::Socket::Method::GET,EndpointGetClients); }); .... if(Vr().webUseSsl) { QFile keyFile(":/path_to.key"); if(!keyFile.open(QIODevice::ReadOnly)) { qWarning()<<"HttpServer::init can't open key"; } QByteArray key_data=keyFile.readAll(); QSslKey key(key_data, QSsl::Rsa,QSsl::Pem,QSsl::PrivateKey,QString("key_secret").toLocal8Bit().data()); QList<QSslCertificate> certs = QSslCertificate::fromPath(":/path_to.crt"); QSslConfiguration config; config.setPrivateKey(key); config.setLocalCertificateChain(certs); server.setSslConfiguration(config); } server.setHandler(&handler); if (!server.listen(QHostAddress(Vr().restApiIp),Vr().restApiPort)) { qCritical()<<"HttpServer::init unable to bind to a local port ip:"<<Vr().restApiIp<<" port:"<<Vr().restApiPort; } else { qDebug()<<"HttpServer::init listening on port:"<<server.serverPort(); } }
Best Regards
Marek