<commit_before>#include <iostream>
#include <thread>
#include <cassert>
#include <cstdio>
#include <signal.h>
#include <unistd.h>
#include "zcm/transport_registrar.h"
using namespace std;

volatile bool running_recv = true;
volatile bool running_send = true;
static void sighandler(int sig) { running_recv = false; }

static zcm_trans_t *makeTransport(const char *url)
{
    auto *u = zcm_url_create(url);
    auto *creator = zcm_transport_find(zcm_url_protocol(u));
    if (!creator)
        return NULL;
    return creator(u);
}

static void send(const char *url)
{
    auto *trans = makeTransport(url);
    assert(trans);

    zcm_msg_t msg;
    msg.channel = "FOO";
    msg.len = 100;
    msg.buf = (char*) malloc(msg.len);
    for (size_t i = 0; i < msg.len; i++)
        msg.buf[i] = (char)(i & 0xff);

    while (running_send) {
        zcm_trans_sendmsg(trans, msg);
        usleep(300000);
    }
}

static void recv(const char *url)
{
    auto *trans = makeTransport(url);
    assert(trans);

    // Tell the transport to give us all of the channels
    zcm_trans_recvmsg_enable(trans, NULL, true);

    while (running_recv) {
        zcm_msg_t msg;
        int ret = zcm_trans_recvmsg(trans, &msg, 100);
        if (ret == ZCM_EOK) {
            printf("recv: got message!\n");
            printf("  channel='%s'\n", msg.channel);
            printf("  len='%zu'\n", msg.len);
            printf("  buf=");
            for (size_t i = 0; i < msg.len; i++) {
                printf("%02x ", msg.buf[i] & 0xff);
            }
            printf("\n");
        }
    }

    // XXX this is a hack for when the recvmsg timeout is not impl correctly
    running_send = false;
}

int main()
{
    signal(SIGINT, sighandler);

    std::thread sendThread {send, "udpm://192.168.3.11?port=7667&ttl=0"};
    std::thread recvThread {recv, "udpm://192.168.3.11?port=7667&ttl=0"};

    recvThread.join();
    sendThread.join();

    return 0;
}<commit_msg>Now verifing every byte sent through the transport implementation<commit_after>#include <iostream>
#include <thread>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <signal.h>
#include <unistd.h>
#include "zcm/transport_registrar.h"
using namespace std;

volatile bool running_recv = true;
volatile bool running_send = true;
static void sighandler(int sig) { running_recv = false; }

static zcm_trans_t *makeTransport(const char *url)
{
    auto *u = zcm_url_create(url);
    auto *creator = zcm_transport_find(zcm_url_protocol(u));
    if (!creator)
        return NULL;
    return creator(u);
}

static zcm_msg_t makeMasterMsg()
{
    zcm_msg_t msg;
    msg.channel = "FOO";
    msg.len = 60000;
    msg.buf = (char*) malloc(msg.len);
    for (size_t i = 0; i < msg.len; i++)
        msg.buf[i] = (char)(i & 0xff);

    return msg;
}

#define fail(...) do {\
    fprintf(stderr, "Err:"); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); exit(1);\
    } while(0)

static void verifySame(zcm_msg_t *a, zcm_msg_t *b)
{
    if (strcmp(a->channel, b->channel) != 0)
        fail("Channels don't match!");
    if (a->len != b->len)
        fail("Lengths don't match!");
    for (size_t i = 0; i < a->len; i++)
        if (a->buf[i] != b->buf[i])
            fail("Data doesn't match at index %d", (int)i);
}

static void send(const char *url)
{
    auto *trans = makeTransport(url);
    assert(trans);

    zcm_msg_t msg = makeMasterMsg();
    while (running_send) {
        zcm_trans_sendmsg(trans, msg);
        usleep(300000);
    }
}

static void recv(const char *url)
{
    auto *trans = makeTransport(url);
    assert(trans);

    // Tell the transport to give us all of the channels
    zcm_trans_recvmsg_enable(trans, NULL, true);

    zcm_msg_t master = makeMasterMsg();
    while (running_recv) {
        zcm_msg_t msg;
        int ret = zcm_trans_recvmsg(trans, &msg, 100);
        if (ret == ZCM_EOK) {
            verifySame(&master, &msg);
        }
    }

    // XXX this is a hack for when the recvmsg timeout is not impl correctly
    running_send = false;
}

int main()
{
    signal(SIGINT, sighandler);

    std::thread sendThread {send, "udpm://192.168.3.11?port=7667&ttl=0"};
    std::thread recvThread {recv, "udpm://192.168.3.11?port=7667&ttl=0"};

    recvThread.join();
    sendThread.join();

    return 0;
}
{'fraction_non_alphanumeric': 0.14710666976528003, 'fraction_numerical': 0.022310016267720195, 'mean_word_length': 2.902085222121487, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '4100626', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1527, 'n_words': 386}