mute the IPC debug messages on stdout

This commit is contained in:
walker0643 2018-01-29 18:53:46 -05:00
parent dbfb04a6ec
commit 31a64731c1
1 changed files with 22 additions and 13 deletions

View File

@ -16,13 +16,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// uncomment to debug this end of IPC chatter
//#define BARRIER_IPC_VERBOSE
#include "IpcReader.h" #include "IpcReader.h"
#include <QTcpSocket> #include <QTcpSocket>
#include "Ipc.h" #include "Ipc.h"
#include <iostream>
#include <QMutex> #include <QMutex>
#include <QByteArray> #include <QByteArray>
#ifdef BARRIER_IPC_VERBOSE
#include <iostream>
#define IPC_LOG(x) (x)
#else // not defined BARRIER_IPC_VERBOSE
#define IPC_LOG(x)
#endif
IpcReader::IpcReader(QTcpSocket* socket) : IpcReader::IpcReader(QTcpSocket* socket) :
m_Socket(socket) m_Socket(socket)
{ {
@ -45,18 +54,18 @@ void IpcReader::stop()
void IpcReader::read() void IpcReader::read()
{ {
QMutexLocker locker(&m_Mutex); QMutexLocker locker(&m_Mutex);
std::cout << "ready read" << std::endl; IPC_LOG(std::cout << "ready read" << std::endl);
while (m_Socket->bytesAvailable()) { while (m_Socket->bytesAvailable()) {
std::cout << "bytes available" << std::endl; IPC_LOG(std::cout << "bytes available" << std::endl);
char codeBuf[5]; char codeBuf[5];
readStream(codeBuf, 4); readStream(codeBuf, 4);
codeBuf[4] = 0; codeBuf[4] = 0;
std::cout << "ipc read: " << codeBuf << std::endl; IPC_LOG(std::cout << "ipc read: " << codeBuf << std::endl);
if (memcmp(codeBuf, kIpcMsgLogLine, 4) == 0) { if (memcmp(codeBuf, kIpcMsgLogLine, 4) == 0) {
std::cout << "reading log line" << std::endl; IPC_LOG(std::cout << "reading log line" << std::endl);
char lenBuf[4]; char lenBuf[4];
readStream(lenBuf, 4); readStream(lenBuf, 4);
@ -70,38 +79,38 @@ void IpcReader::read()
readLogLine(line); readLogLine(line);
} }
else { else {
std::cerr << "aborting, message invalid" << std::endl; IPC_LOG(std::cerr << "aborting, message invalid" << std::endl);
return; return;
} }
} }
std::cout << "read done" << std::endl; IPC_LOG(std::cout << "read done" << std::endl);
} }
bool IpcReader::readStream(char* buffer, int length) bool IpcReader::readStream(char* buffer, int length)
{ {
std::cout << "reading stream" << std::endl; IPC_LOG(std::cout << "reading stream" << std::endl);
int read = 0; int read = 0;
while (read < length) { while (read < length) {
int ask = length - read; int ask = length - read;
if (m_Socket->bytesAvailable() < ask) { if (m_Socket->bytesAvailable() < ask) {
std::cout << "buffer too short, waiting" << std::endl; IPC_LOG(std::cout << "buffer too short, waiting" << std::endl);
m_Socket->waitForReadyRead(-1); m_Socket->waitForReadyRead(-1);
} }
int got = m_Socket->read(buffer, ask); int got = m_Socket->read(buffer, ask);
read += got; read += got;
std::cout << "> ask=" << ask << " got=" << got IPC_LOG(std::cout << "> ask=" << ask << " got=" << got
<< " read=" << read << std::endl; << " read=" << read << std::endl);
if (got == -1) { if (got == -1) {
std::cout << "socket ended, aborting" << std::endl; IPC_LOG(std::cout << "socket ended, aborting" << std::endl);
return false; return false;
} }
else if (length - read > 0) { else if (length - read > 0) {
std::cout << "more remains, seek to " << got << std::endl; IPC_LOG(std::cout << "more remains, seek to " << got << std::endl);
buffer += got; buffer += got;
} }
} }