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

#include "lib.h"
#include "ioloop-internal.h"
#include "ioloop-iolist.h"

bool ioloop_iolist_add(struct io_list *list, struct io_file *io)
{
	int i, idx;

	if ((io->io.condition & IO_READ) != 0)
		idx = IOLOOP_IOLIST_INPUT;
	else if ((io->io.condition & IO_WRITE) != 0)
		idx = IOLOOP_IOLIST_OUTPUT;
	else if ((io->io.condition & IO_ERROR) != 0)
		idx = IOLOOP_IOLIST_ERROR;
	else {
		i_unreached();
	}

	i_assert(list->ios[idx] == NULL);
	list->ios[idx] = io;

	/* check if this was the first one */
	for (i = 0; i < IOLOOP_IOLIST_IOS_PER_FD; i++) {
		if (i != idx && list->ios[i] != NULL)
			return FALSE;
	}

	return TRUE;
}<commit_msg>ioloop: If io_add() is called twice for same fd, give a bit more informative panic message.<commit_after>/*
 * Copyright (c) 2004 <NAME> <<EMAIL>>
 *
 * This software is released under the MIT license.
 */

#include "lib.h"
#include "ioloop-internal.h"
#include "ioloop-iolist.h"

bool ioloop_iolist_add(struct io_list *list, struct io_file *io)
{
	int i, idx;

	if ((io->io.condition & IO_READ) != 0)
		idx = IOLOOP_IOLIST_INPUT;
	else if ((io->io.condition & IO_WRITE) != 0)
		idx = IOLOOP_IOLIST_OUTPUT;
	else if ((io->io.condition & IO_ERROR) != 0)
		idx = IOLOOP_IOLIST_ERROR;
	else {
		i_unreached();
	}

	if (list->ios[idx] != NULL) {
		i_panic("io_add(0x%x) called twice fd=%d, callback=%p -> %p",
			io->io.condition, io->fd, list->ios[idx]->io.callback,
			io->io.callback);
	}
	i_assert(list->ios[idx] == NULL);
	list->ios[idx] = io;

	/* check if this was the first one */
	for (i = 0; i < IOLOOP_IOLIST_IOS_PER_FD; i++) {
		if (i != idx && list->ios[i] != NULL)
			return FALSE;
	}

	return TRUE;
}
{'fraction_non_alphanumeric': 0.17091114883984154, 'fraction_numerical': 0.009620826259196379, 'mean_word_length': 3.752688172043011, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 28, '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': '1646183', 'n_tokens_mistral': 774, 'n_tokens_neox': 727, 'n_words': 184}