<commit_before>#include "messagehandler.h"

#include <QtCore/QDebug>
#include <QtCore/QTime>

#define DEBUG_MESSAGEHANDLER 0

MessageHandler::MessageHandler()
    : m_connectWait(false)
{
}

MessageHandler::~MessageHandler()
{
}

void MessageHandler::expectMessage(const QHostAddress& address)
{
    {
        QMutexLocker locker(&m_connectWaitMutex);
        m_connectWait = true;
    }

    {
        QMutexLocker locker(&m_messageWaitMutex);
        m_messageWait = address;
    }
}

bool MessageHandler::waitForMessage(unsigned long timeout)
{
    QTime time;
    if (timeout != ULONG_MAX)
        time.start();

    {
        QMutexLocker locker(&m_connectWaitMutex);
        if (m_connectWait && !m_connectWaitCondition.wait(&m_connectWaitMutex, timeout))
            return false;
    }

    {
        QMutexLocker locker(&m_messageWaitMutex);
        if (!m_messageWait.isNull() && !m_messageWaitCondition.wait(&m_messageWaitMutex, timeout == ULONG_MAX ? timeout : timeout - time.elapsed()))
            return false;
    }
    return true;
}

void MessageHandler::incomingConnectionInternal(const QHostAddress& address)
{
    emit incomingConnection(address);

    QMutexLocker locker(&m_connectWaitMutex);
    if (m_connectWait) {<commit_msg>Reset the conditions in the case that waitForMessage times out.<commit_after>#include "messagehandler.h"

#include <QtCore/QDebug>
#include <QtCore/QTime>

#define DEBUG_MESSAGEHANDLER 0

MessageHandler::MessageHandler()
    : m_connectWait(false)
{
}

MessageHandler::~MessageHandler()
{
}

void MessageHandler::expectMessage(const QHostAddress& address)
{
    {
        QMutexLocker locker(&m_connectWaitMutex);
        m_connectWait = true;
    }

    {
        QMutexLocker locker(&m_messageWaitMutex);
        m_messageWait = address;
    }
}

bool MessageHandler::waitForMessage(unsigned long timeout)
{
    QTime time;
    if (timeout != ULONG_MAX)
        time.start();

    {
        QMutexLocker locker(&m_connectWaitMutex);
        if (m_connectWait && !m_connectWaitCondition.wait(&m_connectWaitMutex, timeout)) {
            m_connectWait = false;
            return false;
        }
    }

    {
        QMutexLocker locker(&m_messageWaitMutex);
        if (!m_messageWait.isNull() && !m_messageWaitCondition.wait(&m_messageWaitMutex, timeout == ULONG_MAX ? timeout : timeout - time.elapsed())) {
            m_messageWait = QHostAddress();
            return false;
        }
    }
    return true;
}

void MessageHandler::incomingConnectionInternal(const QHostAddress& address)
{
    emit incomingConnection(address);

    QMutexLocker locker(&m_connectWaitMutex);
    if (m_connectWait) {
{'fraction_non_alphanumeric': 0.10425291682348513, 'fraction_numerical': 0.0007527286413248024, 'mean_word_length': 3.4373956594323873, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '630379', 'n_tokens_mistral': 816, 'n_tokens_neox': 821, 'n_words': 145}