QByteArray IpcChannel::receiveMessage(int timeoutMsecs) { disconnect(m_socket, SIGNAL(readyRead()), 0, 0); # ifdef _WIN32 // Win32 workaround - see waitForDisconnected() QElapsedTimer timer; timer.start(); while (m_socket->state() != QLocalSocket::UnconnectedState && (timeoutMsecs == -1 || timer.elapsed() < timeoutMsecs)) { QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); milliSleep(1); if (appendCurrentMessage()) { QByteArray msg = m_message; clearCurrentMessage(); return msg; } } # else while (m_socket->waitForReadyRead(timeoutMsecs)) { if (appendCurrentMessage()) { QByteArray msg = m_message; clearCurrentMessage(); return msg; } } # endif throw DisplazError("Could not read message from socket: %s", m_socket->errorString()); }
/// Read and emit messages until data runs out void IpcChannel::readReadyData() { while (appendCurrentMessage()) { emit messageReceived(m_message); clearCurrentMessage(); } }
QByteArray IpcChannel::receiveMessage(int timeoutMsecs) { disconnect(m_socket, SIGNAL(readyRead()), 0, 0); while (m_socket->waitForReadyRead(timeoutMsecs)) { if (appendCurrentMessage()) { QByteArray msg = m_message; clearCurrentMessage(); return msg; } } throw DisplazError("Could not read message from socket: %s", m_socket->errorString()); connect(m_socket, SIGNAL(readyRead()), this, SLOT(readReadyData())); }