<commit_before>#include "ircd.h"

static void toplev_sync();

void u_toplev_origin_cb(iofd)
struct u_io_fd *iofd;
{
	struct u_conn *conn;

	conn = malloc(sizeof(*conn));
	u_conn_init(conn);
	conn->sock = iofd;

	iofd->priv = conn;

	toplev_sync(iofd);
}

static void toplev_recv(conn)
struct u_conn *conn;
{
	char buf[1024];
	int sz;
	struct u_msg msg;

	sz = recv(conn->sock->fd, buf, 1024-conn->ibuf.pos, 0);
	u_linebuf_data(&conn->ibuf, buf, sz);

	while ((sz = u_linebuf_line(&conn->ibuf, buf, 1024)) != 0) {
		if (sz < 0) /* TODO: error */
			break;
		buf[sz] = '\0';
		if (strlen(buf) != sz) /* TODO: error */
			break;
		u_msg_parse(&msg, buf);
		conn->invoke(conn, &msg);
	}
}

static void toplev_send(iofd)
struct u_io_fd *iofd;
{
	/* TODO: toplev send */
}

static void toplev_sync(iofd)
struct u_io_fd *iofd;<commit_msg>Round off toplev.c<commit_after>#include "ircd.h"

static void toplev_sync();

void u_toplev_origin_cb(iofd)
struct u_io_fd *iofd;
{
	struct u_conn *conn;

	conn = malloc(sizeof(*conn));
	u_conn_init(conn);
	conn->sock = iofd;

	iofd->priv = conn;

	toplev_sync(iofd);
}

static void toplev_recv(iofd)
struct u_io_fd *iofd;
{
	struct u_conn *conn = iofd->priv;
	char buf[1024];
	int sz;
	struct u_msg msg;

	sz = recv(iofd->fd, buf, 1024-conn->ibuf.pos, 0);

	if (sz <= 0) {
		perror("toplev_recv");
		iofd->recv = NULL;
		return;
	}

	u_linebuf_data(&conn->ibuf, buf, sz);

	while ((sz = u_linebuf_line(&conn->ibuf, buf, 1024)) != 0) {
		if (sz < 0) /* TODO: error */
			break;
		buf[sz] = '\0';
		if (strlen(buf) != sz) /* TODO: error */
			break;
		u_msg_parse(&msg, buf);
		conn->invoke(conn, &msg);
	}

	toplev_sync(iofd);
}

static void toplev_send(iofd)
struct u_io_fd *iofd;
{
	struct u_conn *conn = iofd->priv;
	int sz;

	sz = send(iofd->fd, conn->obuf, conn->obuflen, 0);

	if (sz < 0) {
		perror("toplev_send");
		iofd->send = NULL;
		return;
	}

	if (sz > 0) {
		u_memmove(conn->obuf, conn->obuf + sz, conn->obufsize - sz);
		conn->obuflen -= sz;
	}

	toplev_sync(iofd);
}

static void toplev_sync(iofd)
struct u_io_fd *iofd;
{'fraction_non_alphanumeric': 0.1769825918762089, 'fraction_numerical': 0.017408123791102514, 'mean_word_length': 3.8912529550827424, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 30, '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': '3893467', 'n_tokens_mistral': 1011, 'n_tokens_neox': 930, 'n_words': 201}