<commit_before>/*
 * Linux epoll() based ioloop handler.
 *
 * Copyright (c) 2004 <NAME> <<EMAIL>>
 *
 * This software is released under the MIT license.
 */

#include "lib.h"
#include "array.h"
#include "fd-close-on-exec.h"
#include "ioloop-internal.h"
#include "ioloop-iolist.h"

#ifdef IOLOOP_EPOLL

#include <sys/epoll.h>
#include <unistd.h>

struct ioloop_handler_context {
	int epfd;

	unsigned int deleted_count;
	ARRAY_DEFINE(fd_index, struct io_list *);
	ARRAY_DEFINE(events, struct epoll_event);
};

void io_loop_handler_init(struct ioloop *ioloop)
{
	struct ioloop_handler_context *ctx;

	ioloop->handler_context = ctx =
		p_new(ioloop->pool, struct ioloop_handler_context, 1);

	p_array_init(&ctx->events, ioloop->pool, IOLOOP_INITIAL_FD_COUNT);
	p_array_init(&ctx->fd_index, ioloop->pool, IOLOOP_INITIAL_FD_COUNT);

	ctx->epfd = epoll_create(IOLOOP_INITIAL_FD_COUNT);
	if (ctx->epfd < 0)
		i_fatal("epoll_create(): %m");
	fd_close_on_exec(ctx->epfd, TRUE);
}

void io_loop_handler_deinit(struct ioloop *ioloop)
{
	struct ioloop_handler_context *ctx = ioloop->handler_context;

	if (close(ctx->epfd) < 0)
		i_error("close(epoll) failed: %m");
	array_free(&ioloop->handler_context->fd_index);
	array_free(&ioloop->handler_context->events);
	p_free(ioloop->pool, ioloop->handler_context);
}

#define IO_EPOLL_ERROR (EPOLLERR | EPOLLHUP)
#define IO_EPOLL_INPUT (EPOLLIN | EPOLLPRI | IO_EPOLL_ERROR)
#define IO_EPOLL_OUTPUT	(EPOLLOUT | IO_EPOLL_ERROR)

static int epoll_event_mask(struct io_list *list)
{
	int events = 0, i;<commit_msg>Free all the used memory when destroying the ioloop.<commit_after>/*
 * Linux epoll() based ioloop handler.
 *
 * Copyright (c) 2004 <NAME> <<EMAIL>>
 *
 * This software is released under the MIT license.
 */

#include "lib.h"
#include "array.h"
#include "fd-close-on-exec.h"
#include "ioloop-internal.h"
#include "ioloop-iolist.h"

#ifdef IOLOOP_EPOLL

#include <sys/epoll.h>
#include <unistd.h>

struct ioloop_handler_context {
	int epfd;

	unsigned int deleted_count;
	ARRAY_DEFINE(fd_index, struct io_list *);
	ARRAY_DEFINE(events, struct epoll_event);
};

void io_loop_handler_init(struct ioloop *ioloop)
{
	struct ioloop_handler_context *ctx;

	ioloop->handler_context = ctx =
		p_new(ioloop->pool, struct ioloop_handler_context, 1);

	p_array_init(&ctx->events, ioloop->pool, IOLOOP_INITIAL_FD_COUNT);
	p_array_init(&ctx->fd_index, ioloop->pool, IOLOOP_INITIAL_FD_COUNT);

	ctx->epfd = epoll_create(IOLOOP_INITIAL_FD_COUNT);
	if (ctx->epfd < 0)
		i_fatal("epoll_create(): %m");
	fd_close_on_exec(ctx->epfd, TRUE);
}

void io_loop_handler_deinit(struct ioloop *ioloop)
{
	struct ioloop_handler_context *ctx = ioloop->handler_context;
	struct io_list **list;
	unsigned int i, count;

	list = array_get_modifyable(&ctx->fd_index, &count);
	for (i = 0; i < count; i++)
		p_free(ioloop->pool, list[i]);

	if (close(ctx->epfd) < 0)
		i_error("close(epoll) failed: %m");
	array_free(&ioloop->handler_context->fd_index);
	array_free(&ioloop->handler_context->events);
	p_free(ioloop->pool, ioloop->handler_context);
}

#define IO_EPOLL_ERROR (EPOLLERR | EPOLLHUP)
#define IO_EPOLL_INPUT (EPOLLIN | EPOLLPRI | IO_EPOLL_ERROR)
#define IO_EPOLL_OUTPUT	(EPOLLOUT | IO_EPOLL_ERROR)

static int epoll_event_mask(struct io_list *list)
{
	int events = 0, i;
{'fraction_non_alphanumeric': 0.13517618469015796, 'fraction_numerical': 0.005164034021871203, 'mean_word_length': 5.976694915254237, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 49, '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': '4855839', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1328, 'n_words': 257}