<commit_before>#include "zwssock.h"
#include "zwshandshake.h"
#include "zwsdecoder.h"

#include <czmq.h>
#include <string.h>

struct _zwssock_t
{
	zctx_t *ctx;                //  Our parent context
	void *control;              //  Control to/from agent
	void *data;                 //  Data to/from agent
};

//  This background thread does all the real work
static void s_agent_task(void *args, zctx_t *ctx, void *control);

//  --------------------------------------------------------------------------
//  Constructor

zwssock_t* zwssock_new_router(zctx_t *ctx)
{
	zwssock_t *self = (zwssock_t *)zmalloc(sizeof(zwssock_t));

	assert(self);

	self->ctx = ctx;
	self->control = zthread_fork(self->ctx, s_agent_task, NULL);

	//  Create separate data socket, send address on control socket
	self->data = zsocket_new(self->ctx, ZMQ_PAIR);
	assert(self->data);
	int rc = zsocket_bind(self->data, "inproc://data-%p", self->data);
	assert(rc != -1);
	zstr_sendf(self->control, "inproc://data-%p", self->data);

	return self;
}

//  --------------------------------------------------------------------------
//  Destructor

void zwssock_destroy(zwssock_t **self_p)
{
	assert(self_p);
	if (*self_p) {
		zwssock_t *self = *self_p;
		zstr_send(self->control, "TERMINATE");

		free(zstr_recv(self->control));
		free(self);
		*self_p = NULL;
	}
}

int zwssock_bind(zwssock_t *self, char *endpoint)
{
	assert(self);
	zstr_sendx(self->control, "BIND", endpoint, NULL);
}

int zwssock_send(zwssock_t *self, zmsg_t **msg_p)
{
	assert(self);
	assert(zmsg_size(*msg_p) > 0);
	zmsg_send(msg_p, self->data);
	return 0;
}

zmsg_t * zwssock_recv(zwssock_t *self)
{
	assert(self);
	zmsg_t *msg = zmsg_recv(self->data);
	return msg;
}

void* zwssock_handle(zwssock_t *self)
{
	assert(self);
	return self->data;
}


//  *************************    BACK END AGENT    *************************

typedef struct {<commit_msg>zwssock.c: return value in int function<commit_after>#include "zwssock.h"
#include "zwshandshake.h"
#include "zwsdecoder.h"

#include <czmq.h>
#include <string.h>

struct _zwssock_t
{
	zctx_t *ctx;                //  Our parent context
	void *control;              //  Control to/from agent
	void *data;                 //  Data to/from agent
};

//  This background thread does all the real work
static void s_agent_task(void *args, zctx_t *ctx, void *control);

//  --------------------------------------------------------------------------
//  Constructor

zwssock_t* zwssock_new_router(zctx_t *ctx)
{
	zwssock_t *self = (zwssock_t *)zmalloc(sizeof(zwssock_t));

	assert(self);

	self->ctx = ctx;
	self->control = zthread_fork(self->ctx, s_agent_task, NULL);

	//  Create separate data socket, send address on control socket
	self->data = zsocket_new(self->ctx, ZMQ_PAIR);
	assert(self->data);
	int rc = zsocket_bind(self->data, "inproc://data-%p", self->data);
	assert(rc != -1);
	zstr_sendf(self->control, "inproc://data-%p", self->data);

	return self;
}

//  --------------------------------------------------------------------------
//  Destructor

void zwssock_destroy(zwssock_t **self_p)
{
	assert(self_p);
	if (*self_p) {
		zwssock_t *self = *self_p;
		zstr_send(self->control, "TERMINATE");

		free(zstr_recv(self->control));
		free(self);
		*self_p = NULL;
	}
}

int zwssock_bind(zwssock_t *self, char *endpoint)
{
	assert(self);
	return zstr_sendx(self->control, "BIND", endpoint, NULL);
}

int zwssock_send(zwssock_t *self, zmsg_t **msg_p)
{
	assert(self);
	assert(zmsg_size(*msg_p) > 0);
	zmsg_send(msg_p, self->data);
	return 0;
}

zmsg_t * zwssock_recv(zwssock_t *self)
{
	assert(self);
	zmsg_t *msg = zmsg_recv(self->data);
	return msg;
}

void* zwssock_handle(zwssock_t *self)
{
	assert(self);
	return self->data;
}


//  *************************    BACK END AGENT    *************************

typedef struct {
{'fraction_non_alphanumeric': 0.2417123466457844, 'fraction_numerical': 0.0015661707126076742, 'mean_word_length': 2.8243512974051894, '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': '7289852', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1411, 'n_words': 288}