size hack for gui ipc (only temporary)
This commit is contained in:
parent
e0098d5c8f
commit
bab317931b
|
@ -18,6 +18,7 @@
|
|||
#include "IpcClient.h"
|
||||
#include <QTcpSocket>
|
||||
#include <QHostAddress>
|
||||
#include <iostream>
|
||||
|
||||
IpcClient::IpcClient()
|
||||
{
|
||||
|
@ -39,6 +40,8 @@ void IpcClient::read()
|
|||
{
|
||||
QDataStream stream(m_Socket);
|
||||
|
||||
while (m_Socket->bytesAvailable() != 0) {
|
||||
|
||||
char codeBuf[1];
|
||||
stream.readRawData(codeBuf, 1);
|
||||
|
||||
|
@ -49,13 +52,26 @@ void IpcClient::read()
|
|||
stream.readRawData(lenBuf, 2);
|
||||
int len = (lenBuf[0] << 8) + lenBuf[1];
|
||||
|
||||
char* data = new char[len];
|
||||
stream.readRawData(data, len);
|
||||
// HACK: sometimes the size is wrong (probably a bug in the above code)
|
||||
// but the following text always seems to be valid, so just read a large
|
||||
// amount from the buffer and put a \0 at the end if the number looks
|
||||
// valid (ugh, this sucks).
|
||||
char* data = new char[1024];
|
||||
stream.readRawData(data, 1024);
|
||||
if (len > -1) {
|
||||
data[len] = '\0';
|
||||
}
|
||||
|
||||
QString s = QString::fromUtf8(data, len);
|
||||
QString s = QString::fromUtf8(data);
|
||||
readLogLine(s);
|
||||
}
|
||||
break;
|
||||
|
||||
default: {
|
||||
std::cerr << "invalid code: " << codeBuf[0] << std::endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue