<commit_before>#if 0
#include "libwebsockets.h"
#include <stdio.h>

static int ws_callback(
        struct libwebsocket_context *this,
        struct libwebsocket *wsi,
        enum libwebsocket_callback_reasons reason,
        void *user,
        void *in,
        size_t len)
{
    switch (reason)
    {
        case LWS_CALLBACK_CLIENT_ESTABLISHED:
            fprintf(stderr, "ws_callback: LWS_CALLBACK_CLIENT_ESTABLISHED\n");
            break;
        case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
            fprintf(stderr, "ws_callback: LWS_CALLBACK_CLIENT_CONNECTION_ERROR\n");
            break;
        case LWS_CALLBACK_CLOSED:
            fprintf(stderr, "ws_callback: LWS_CALLBACK_CLOSED\n");
            break;
        case LWS_CALLBACK_CLIENT_RECEIVE:
            ((char *)in)[len] = '\0';
            fprintf(stderr, "rx %d '%s'\n", (int)len, (char *)in);
            break;
        /*case LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED:*/
        default:
            break;
    }
    return 0;
}

#define CANOPY_WS_PORT 1235
#define CANOPY_WS_USE_SSL 1
#define CANOPY_WS_ADDRESS "123-fake-st"
static struct libwebsocket_protocols sCanopyWsProtocols[] = {
    {
        "canopy-ws-protocol",
        ws_callback,
        0,
        128
    },
    { NULL, NULL, 0, 0 } /* end */
};

int ws_main()
{
    struct lws_context_creation_info info;
    struct libwebsocket *wsi;
    struct libwebsocket_context *context;
    info.port = CANOPY_WS_PORT;
    info.protocols = sCanopyWsProtocols;
    info.gid = -1;
    info.uid = -1;

    context = libwebsocket_create_context(&info);
    if (!context)
    {
        fprintf(stderr, "Failed to create libwebsocket context\n");
        return 1;
    }

    wsi = libwebsocket_client_connect(
            context, 
            CANOPY_WS_ADDRESS, 
            CANOPY_WS_PORT, 
            CANOPY_WS_USE_SSL, 
            "/",
            0, /*?*/
            0, /*?*/
            "canopy-ws-protocol",
            -1 /* latest ietf version */
        );
    if (!wsi)
    {
        fprintf(stderr, "Failed to create libwebsocket connection\n");
        return 1;
    }

    int result;
    while (result != 0)
    {
        result = libwebsocket_service(context, 0);
    }

    libwebsocket_context_destroy(context);
    return 0;
}
#endif<commit_msg>Get websocket code working against test echo server<commit_after>#include "canopy.h"
#include "libwebsockets.h"
#include <stdio.h>
#include <string.h>

static int ws_callback(
        struct libwebsocket_context *this,
        struct libwebsocket *wsi,
        enum libwebsocket_callback_reasons reason,
        void *user,
        void *in,
        size_t len)
{
    switch (reason)
    {
        case LWS_CALLBACK_CLIENT_ESTABLISHED:
            fprintf(stderr, "ws_callback: LWS_CALLBACK_CLIENT_ESTABLISHED\n");
            libwebsocket_callback_on_writable(this, wsi);
            break;
        case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
            fprintf(stderr, "ws_callback: LWS_CALLBACK_CLIENT_CONNECTION_ERROR\n");
            break;
        case LWS_CALLBACK_CLOSED:
            fprintf(stderr, "ws_callback: LWS_CALLBACK_CLOSED\n");
            break;

        case LWS_CALLBACK_CLIENT_WRITEABLE:
        {
            char buf[LWS_SEND_BUFFER_PRE_PADDING + 6 + LWS_SEND_BUFFER_POST_PADDING];
            strcpy(&buf[LWS_SEND_BUFFER_PRE_PADDING], "hello");
            printf("Saying hi:\n");
            libwebsocket_write(wsi, (unsigned char *)&buf[LWS_SEND_BUFFER_PRE_PADDING], 6, LWS_WRITE_TEXT);
            libwebsocket_callback_on_writable(this, wsi);
            break;
        }
        case LWS_CALLBACK_CLIENT_RECEIVE:
            ((char *)in)[len] = '\0';
            fprintf(stderr, "rx %d '%s'\n", (int)len, (char *)in);
            break;
        /*case LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED:*/
        default:
            break;
    }
    return 0;
}

//#define CANOPY_WS_PORT 1235
#define CANOPY_WS_PORT CONTEXT_PORT_NO_LISTEN
#define CANOPY_WS_USE_SSL 0
#define CANOPY_WS_ADDRESS "echo.websocket.org"
static struct libwebsocket_protocols sCanopyWsProtocols[] = {
    {
        "echo",
        ws_callback,
        1024,
        1024,
        0,
        NULL,
        0
    },
    { NULL, NULL, 0, 0, 0, NULL, 0} /* end */
};

int ws_main()
{
    struct lws_context_creation_info info={0};
    struct libwebsocket *wsi;
    struct libwebsocket_context *context;
    info.port = CONTEXT_PORT_NO_LISTEN;
    info.iface = NULL;
    info.protocols = sCanopyWsProtocols;
    info.extensions = NULL;
    info.ssl_cert_filepath = NULL;
    info.ssl_private_key_filepath = NULL;
    info.ssl_ca_filepath = NULL;
    info.ssl_cipher_list = NULL;
    info.gid = -1;
    info.uid = -1;
    info.options = 0;
    info.user = NULL;
    info.ka_time = 0;
    info.ka_probes = 0;
    info.ka_interval = 0;

    //lws_set_log_level(511, NULL);

    context = libwebsocket_create_context(&info);
    if (!context)
    {
        fprintf(stderr, "Failed to create libwebsocket context\n");
        return 1;
    }

    wsi = libwebsocket_client_connect(
            context, 
            CANOPY_WS_ADDRESS, 
            80, 
            CANOPY_WS_USE_SSL, 
            "/",
            "echo.websocket.org", /*host?*/
            "http://gregprisament.com", /*origin?*/
            "echo",
            -1 /* latest ietf version */
        );
    if (!wsi)
    {
        fprintf(stderr, "Failed to create libwebsocket connection\n");
        return 1;
    }

    int result;
   // do
    //{
        result = libwebsocket_service(context, 800);
        result = libwebsocket_service(context, 800);
        result = libwebsocket_service(context, 800);
        result = libwebsocket_service(context, 800);
        result = libwebsocket_service(context, 800);
        result = libwebsocket_service(context, 800);
        result = libwebsocket_service(context, 800);
        result = libwebsocket_service(context, 800);
        result = libwebsocket_service(context, 800);
        result = libwebsocket_service(context, 800);
        result = libwebsocket_service(context, 800);
    //} while (result == 0);

        printf("Goodbye:\n");
    libwebsocket_context_destroy(context);
    return result;
}

bool canopy_connect(CanopyContext canopy, const char *websocket_url)
{
    ws_main();
    return true;
}
{'fraction_non_alphanumeric': 0.10330121623756121, 'fraction_numerical': 0.015637340072658348, 'mean_word_length': 2.2859366891541257, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '5686719', 'n_tokens_mistral': 2221, 'n_tokens_neox': 2089, 'n_words': 406}