I'm puzzled with a problem designing a simple QLocalServer-QLocalSocket IPC system.
The QLocalServer waits for a new connection and connect the signals to the proper slots.
void CommandProcessor::onNewConnection()
{
QLocalSocket* pLocal = _server->nextPendingConnection();
connect(pLocal,SIGNAL(disconnected()),this,SLOT(onSocketDisconnected()));
connect(pLocal,SIGNAL(readyRead()),this,SLOT(onSocketReadyRead()));
connect(pLocal,SIGNAL(error(QLocalSocket::LocalSocketError)),this, SLOT(onSocketError(QLocalSocket::LocalSocketError)));
qDebug("Socket connected. addr=%p", pLocal);
}
The readyRead slot implementation is:
void CommandProcessor::onSocketReadyRead()
{
QLocalSocket* pLocalSocket = (QLocalSocket *) sender();
qDebug("SocketReadyRead. addr=%p", pLocalSocket);
QDataStream in(pLocalSocket);
in.setVersion(QDataStream::Qt_5_2);
pLocalSocket->readAll();
qDebug("%s pLocalSocket->bytesAvailable() = %d", Q_FUNC_INFO, pLocalSocket->bytesAvailable());
}
This readAll is done intentionally to check how i'm getting two readyRead signals in sequence (from the same slot pointer, I verified that).
The client operation is fairly straightforward:
QByteArray data;
QDataStream out(&data, QIODevice::ReadWrite);
out.setVersion(QDataStream::Qt_5_2);
cmd.toDataStream(out);
// write blocksize at first field
out.device()->seek(0);
out << data.size() - sizeof(BLOCKSIZE_T);
qint64 bw = _socket->write(data);
The _socket->write(data) call triggers duplicate readyRead at server (even when the server side has read all data with ReadAll call).
Any indication of where I should look?