<commit_before>#include "delegate/Glue.hxx"
#include "delegate/Handler.hxx"
#include "delegate/Stock.hxx"
#include "spawn/ChildOptions.hxx"
#include "stock/MapStock.hxx"
#include "async.hxx"
#include "event/defer.hxx"
#include "pool.hxx"

#include <glib.h>

#include <event.h>

#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

static const char helper_path[] = "./cm4all-beng-proxy-delegate-helper";
static StockMap *delegate_stock;
static struct pool *pool;

static void
my_stop(void *ctx gcc_unused)
{
    hstock_free(delegate_stock);
}

class MyDelegateHandler final : public DelegateHandler {
public:
    void OnDelegateSuccess(int fd) override {
        close(fd);

        defer(pool, my_stop, nullptr, nullptr);
    }

    void OnDelegateError(GError *error) override {
        g_printerr("%s\n", error->message);
        g_error_free(error);

        defer(pool, my_stop, nullptr, nullptr);
    }
};

int main(int argc, char **argv)
{
    struct event_base *event_base;
    struct pool *root_pool;
    struct async_operation_ref my_async_ref;

    if (argc != 2) {
        fprintf(stderr, "usage: run-delegate PATH\n");
        return 1;
    }

    event_base = event_init();

    root_pool = pool_new_libc(NULL, "root");
    delegate_stock = delegate_stock_new(root_pool);
    pool = pool_new_linear(root_pool, "test", 8192);

    ChildOptions child_options;
    child_options.Init();

    MyDelegateHandler handler;
    delegate_stock_open(delegate_stock, pool, helper_path, child_options,<commit_msg>test/run_delegate: use class DeferEvent instead of defer()<commit_after>#include "delegate/Glue.hxx"
#include "delegate/Handler.hxx"
#include "delegate/Stock.hxx"
#include "spawn/ChildOptions.hxx"
#include "stock/MapStock.hxx"
#include "async.hxx"
#include "event/DeferEvent.hxx"
#include "event/Callback.hxx"
#include "pool.hxx"

#include <glib.h>

#include <event.h>

#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

static const char helper_path[] = "./cm4all-beng-proxy-delegate-helper";
static StockMap *delegate_stock;
static struct pool *pool;

class MyDelegateHandler final : public DelegateHandler {
    DeferEvent defer;

public:
    MyDelegateHandler()
        :defer(MakeSimpleEventCallback(MyDelegateHandler, Stop), this) {}

    void Stop() {
        hstock_free(delegate_stock);
    }

    void OnDelegateSuccess(int fd) override {
        close(fd);

        defer.Add();
    }

    void OnDelegateError(GError *error) override {
        g_printerr("%s\n", error->message);
        g_error_free(error);

        defer.Add();
    }
};

int main(int argc, char **argv)
{
    struct event_base *event_base;
    struct pool *root_pool;
    struct async_operation_ref my_async_ref;

    if (argc != 2) {
        fprintf(stderr, "usage: run-delegate PATH\n");
        return 1;
    }

    event_base = event_init();

    root_pool = pool_new_libc(NULL, "root");
    delegate_stock = delegate_stock_new(root_pool);
    pool = pool_new_linear(root_pool, "test", 8192);

    ChildOptions child_options;
    child_options.Init();

    MyDelegateHandler handler;
    delegate_stock_open(delegate_stock, pool, helper_path, child_options,
{'fraction_non_alphanumeric': 0.12445550715619166, 'fraction_numerical': 0.0043559427504667085, 'mean_word_length': 3.9159021406727827, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '5248358', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1076, 'n_words': 234}