#include "test_producer_consumer.h"

#include <mesytec-mvlc/mesytec-mvlc.h>

int main()
{
    spdlog::set_level(spdlog::level::info);
    auto producerSocket = make_pair_socket();

    if (int res = nng_listen(producerSocket, "inproc://1", nullptr, 0))
        mnode_nng_fatal("nng_listen inproc", res);

    auto consumerSocket = make_pair_socket();

    if (int res = nng_dial(consumerSocket, "inproc://1", nullptr, 0))
        mnode_nng_fatal("nng_dial", res);

    std::vector<std::thread> threads;

    threads.emplace_back(std::thread(producer, producerSocket));
    threads.emplace_back(std::thread(consumer, consumerSocket));

    for (auto &t: threads)
        if (t.joinable()) t.join();

    if (int res = nng_close(consumerSocket))
        mnode_nng_fatal("nng_close", res);

    if (int res = nng_close(producerSocket))
        mnode_nng_fatal("nng_close", res);

    return 0;
}
