bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
72a7c4f2ba93a723e23c941369a2985d75f240c9Stephan Boschstatic void timeout_callback(struct timeval *tv)
cca98b5accbfff773731a206950114acb8dcacfdAki Tuomistatic void test_ioloop_fd_cb_left(struct test_ctx *ctx)
cca98b5accbfff773731a206950114acb8dcacfdAki Tuomistatic void test_ioloop_fd_cb_right(struct test_ctx *ctx)
cca98b5accbfff773731a206950114acb8dcacfdAki Tuomistatic void test_ioloop_fd_to(struct test_ctx *ctx)
cca98b5accbfff773731a206950114acb8dcacfdAki Tuomi int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
cca98b5accbfff773731a206950114acb8dcacfdAki Tuomi struct timeout *to = timeout_add(2000, test_ioloop_fd_to, &test_ctx);
9b3565b09683b48f66de51aebb52786934d1c324Timo Sirainen /* add a timeout by moving it from another ioloop */
9b3565b09683b48f66de51aebb52786934d1c324Timo Sirainen to2 = timeout_add(1000, timeout_callback, &tv_callback);
9b3565b09683b48f66de51aebb52786934d1c324Timo Sirainen /* add & remove immediately */
72a7c4f2ba93a723e23c941369a2985d75f240c9Stephan Bosch to = timeout_add(1000, timeout_callback, &tv_callback);
9b3565b09683b48f66de51aebb52786934d1c324Timo Sirainen /* add the timeout we're actually testing below */
72a7c4f2ba93a723e23c941369a2985d75f240c9Stephan Bosch to = timeout_add(1000, timeout_callback, &tv_callback);
72a7c4f2ba93a723e23c941369a2985d75f240c9Stephan Bosch test_assert(timeval_diff_msecs(&tv_callback, &tv_start) >= 500);
7f52e276c1bf13b4809344492023b90e46c3ac5dTimo Sirainenstatic void io_callback(void *context ATTR_UNUSED)
7f52e276c1bf13b4809344492023b90e46c3ac5dTimo Sirainenstatic void test_ioloop_find_fd_conditions(void)
b7324e421e2132cbbf753e6fdbe675bbaecdf929Timo Sirainen static struct {
7f52e276c1bf13b4809344492023b90e46c3ac5dTimo Sirainen { IO_READ, { -1, -1 }, NULL } /* read+write as separate ios */
7f52e276c1bf13b4809344492023b90e46c3ac5dTimo Sirainen unsigned int i;
7f52e276c1bf13b4809344492023b90e46c3ac5dTimo Sirainen if (socketpair(AF_UNIX, SOCK_STREAM, 0, tests[i].fd) < 0)
677b75f90d81eafe742896d6570a2f63ce501d05Josef 'Jeff' Sipek tests[i].io = io_add(tests[i].fd[0], tests[i].condition, io_callback, NULL);
677b75f90d81eafe742896d6570a2f63ce501d05Josef 'Jeff' Sipek io = io_add(tests[i-1].fd[0], IO_WRITE, io_callback, NULL);
7f52e276c1bf13b4809344492023b90e46c3ac5dTimo Sirainen test_assert_idx(io_loop_find_fd_conditions(ioloop, tests[i].fd[0]) == tests[i].condition, i);
e5a55bb6b867ee3ed95ac216996ff2e24bd596ccAki Tuomistatic void io_callback_pending_io(void *context ATTR_UNUSED)
e5a55bb6b867ee3ed95ac216996ff2e24bd596ccAki Tuomi struct istream *is = i_stream_create_from_data("data", 4);