<commit_before>#include "uv_tls.h"
#include <assert.h>

static void alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf)
{
    buf->base = (char*)malloc(size);
    memset(buf->base, 0, size);
    buf->len = size;
    assert(buf->base != NULL && "Memory allocation failed");
}


int uv_tls_init(uv_loop_t *loop, evt_ctx_t *ctx, uv_tls_t *endpt)
{
    memset( endpt, 0, sizeof *endpt);

    assert(0 == uv_tcp_init(loop, &(endpt->skt)));

    evt_tls_t *t = evt_ctx_get_tls(ctx);
    assert( t != NULL );

    t->data = endpt;

    endpt->tls = t;
    endpt->tls_rd_cb = NULL;
    endpt->tls_cnct_cb = NULL;
    endpt->tls_cls_cb = NULL;
    endpt->tls_accpt_cb = NULL;
    return 0;
}

void on_tcp_read(uv_stream_t *stream, ssize_t nrd, const uv_buf_t *data)
{
    uv_tls_t *parent = CONTAINER_OF(stream, uv_tls_t, skt);
    assert( parent != NULL);
    if ( nrd <= 0 ) {
        if( nrd == UV_EOF) {
            uv_tls_close((uv_handle_t*)stream, (uv_close_cb)free);
        }
        free(data->base);
        return;
    }
    evt_tls_feed_data(parent->tls, data->base, nrd);
    free(data->base);
}



static void on_hd_complete( evt_tls_t *t, int status)
{

    uv_tls_t *ut = (uv_tls_t*)t->data;
    assert( ut != NULL && ut->tls_accpt_cb != NULL);
    ut->tls_accpt_cb(ut, status -1);<commit_msg>return proper value for uv_tls_init<commit_after>#include "uv_tls.h"
#include <assert.h>

static void alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf)
{
    buf->base = (char*)malloc(size);
    memset(buf->base, 0, size);
    buf->len = size;
    assert(buf->base != NULL && "Memory allocation failed");
}


int uv_tls_init(uv_loop_t *loop, evt_ctx_t *ctx, uv_tls_t *endpt)
{
    int r = 0;
    memset( endpt, 0, sizeof *endpt);

    r = uv_tcp_init(loop, &(endpt->skt)));

    evt_tls_t *t = evt_ctx_get_tls(ctx);
    assert( t != NULL );

    t->data = endpt;

    endpt->tls = t;
    endpt->tls_rd_cb = NULL;
    endpt->tls_cnct_cb = NULL;
    endpt->tls_cls_cb = NULL;
    endpt->tls_accpt_cb = NULL;
    return r;
}

void on_tcp_read(uv_stream_t *stream, ssize_t nrd, const uv_buf_t *data)
{
    uv_tls_t *parent = CONTAINER_OF(stream, uv_tls_t, skt);
    assert( parent != NULL);
    if ( nrd <= 0 ) {
        if( nrd == UV_EOF) {
            uv_tls_close((uv_handle_t*)stream, (uv_close_cb)free);
        }
        free(data->base);
        return;
    }
    evt_tls_feed_data(parent->tls, data->base, nrd);
    free(data->base);
}



static void on_hd_complete( evt_tls_t *t, int status)
{

    uv_tls_t *ut = (uv_tls_t*)t->data;
    assert( ut != NULL && ut->tls_accpt_cb != NULL);
    ut->tls_accpt_cb(ut, status -1);
{'fraction_non_alphanumeric': 0.1551267499054105, 'fraction_numerical': 0.004161937192584185, 'mean_word_length': 3.124804992199688, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, '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': '3532666', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1089, 'n_words': 220}