From 2d6b6d4da1d9732b2b02989a4374d356ff840d1b Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 26 Oct 2026 20:03:22 +0100 Subject: Replace libowfat's event waiter with our own abstraction It's with a heavy heart that I remove libowfat as my event library from opentracker. libowfat is what taught opentracker to walk and then fly. The tracker was literally standing on the shoulder of giants when I started writing it in 2006. For its time, the event abstraction was unparalleled and it has held up for many years, and it served the bittorrent community greatly. https://erdgeist.org/gitweb/opentracker/commit/?id=ad472597c569568bad0526d116b601dfcb36638c Unfortunately, it is very likely that libowfat will not be maintained anymore for the foreseeable future, it is already not easy to get its source from upstream and opentracker started receiving bug reports that I can not reasonably answer or patch. Before the project gets more dependent on the limitations of libowfat's current state, I need to teach opentracker to stand on its own feet and fly by itself. I've learned a great deal in the process and have even more respect now for what libowfat pioneered. The path for opentracker is cleared now. Ground work has already been laid in the migration process to support multi threaded http processing while keeping the aggressive reduction of syscalls alive that made the libowfat+opentracker combo so scalable. Here be some dragons, though: Even though there is a unit test suite now, the event loop's rewrite has not been battle tested yet. So you might want to hold up for a bit before jumping on the solo band wagon. What awaits at the end will be a long overdue v1.0, which will be named in honour of Felix. --- tests/t_event.c | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/t_event.c b/tests/t_event.c index 306f8cd..5509f19 100644 --- a/tests/t_event.c +++ b/tests/t_event.c @@ -59,18 +59,18 @@ static void case_readable(void) { test_case("a descriptor with something to read is reported, with its generation"); pair_open(); CHECK(sv[0] != -1); - CHECK_INT(event_add(sv[0], EVENT_READ, 4711), 0); + CHECK_INT(event_add(sv[0], EVENT_IN, 4711), 0); CHECK_INT(write(sv[1], "x", 1), 1); - CHECK_INT(wait_for(sv[0], EVENT_READ, 1000, &generation), 1); + CHECK_INT(wait_for(sv[0], EVENT_IN, 1000, &generation), 1); CHECK_INT(generation, 4711); test_case("and keeps being reported until it is read"); - CHECK_INT(wait_for(sv[0], EVENT_READ, 1000, NULL), 1); + CHECK_INT(wait_for(sv[0], EVENT_IN, 1000, NULL), 1); { char scratch[4]; CHECK_INT(read(sv[0], scratch, sizeof(scratch)), 1); } - CHECK_INT(wait_for(sv[0], EVENT_READ, 50, NULL), 0); + CHECK_INT(wait_for(sv[0], EVENT_IN, 50, NULL), 0); CHECK_INT(event_del(sv[0]), 0); pair_close(); @@ -80,12 +80,12 @@ static void case_writable(void) { test_case("a descriptor with room to write is reported"); pair_open(); CHECK(sv[0] != -1); - CHECK_INT(event_add(sv[0], EVENT_WRITE, 1), 0); - CHECK_INT(wait_for(sv[0], EVENT_WRITE, 1000, NULL), 1); + CHECK_INT(event_add(sv[0], EVENT_OUT, 1), 0); + CHECK_INT(wait_for(sv[0], EVENT_OUT, 1000, NULL), 1); test_case("and is not, once we say we no longer care"); - CHECK_INT(event_modify(sv[0], EVENT_READ, 1), 0); - CHECK_INT(wait_for(sv[0], EVENT_WRITE, 50, NULL), 0); + CHECK_INT(event_modify(sv[0], EVENT_IN, 1), 0); + CHECK_INT(wait_for(sv[0], EVENT_OUT, 50, NULL), 0); CHECK_INT(event_del(sv[0]), 0); pair_close(); @@ -95,13 +95,13 @@ static void case_interest_is_separate(void) { test_case("asking only about writing does not report reading"); pair_open(); CHECK(sv[0] != -1); - CHECK_INT(event_add(sv[0], EVENT_WRITE, 1), 0); + CHECK_INT(event_add(sv[0], EVENT_OUT, 1), 0); CHECK_INT(write(sv[1], "x", 1), 1); - CHECK_INT(wait_for(sv[0], EVENT_READ, 50, NULL), 0); + CHECK_INT(wait_for(sv[0], EVENT_IN, 50, NULL), 0); test_case("until we ask about it"); - CHECK_INT(event_modify(sv[0], EVENT_READ | EVENT_WRITE, 1), 0); - CHECK_INT(wait_for(sv[0], EVENT_READ, 1000, NULL), 1); + CHECK_INT(event_modify(sv[0], EVENT_IN | EVENT_OUT, 1), 0); + CHECK_INT(wait_for(sv[0], EVENT_IN, 1000, NULL), 1); CHECK_INT(event_del(sv[0]), 0); pair_close(); @@ -111,11 +111,11 @@ static void case_removed_is_silent(void) { test_case("a removed descriptor is not reported again"); pair_open(); CHECK(sv[0] != -1); - CHECK_INT(event_add(sv[0], EVENT_READ, 1), 0); + CHECK_INT(event_add(sv[0], EVENT_IN, 1), 0); CHECK_INT(write(sv[1], "x", 1), 1); - CHECK_INT(wait_for(sv[0], EVENT_READ, 1000, NULL), 1); + CHECK_INT(wait_for(sv[0], EVENT_IN, 1000, NULL), 1); CHECK_INT(event_del(sv[0]), 0); - CHECK_INT(wait_for(sv[0], EVENT_READ, 50, NULL), 0); + CHECK_INT(wait_for(sv[0], EVENT_IN, 50, NULL), 0); pair_close(); } @@ -127,21 +127,21 @@ static void case_generations_do_not_mix(void) { pair_open(); CHECK(sv[0] != -1); CHECK_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, other), 0); - CHECK_INT(event_add(sv[0], EVENT_READ, 100), 0); - CHECK_INT(event_add(other[0], EVENT_READ, 200), 0); + CHECK_INT(event_add(sv[0], EVENT_IN, 100), 0); + CHECK_INT(event_add(other[0], EVENT_IN, 200), 0); CHECK_INT(write(sv[1], "x", 1), 1); CHECK_INT(write(other[1], "y", 1), 1); - CHECK_INT(wait_for(sv[0], EVENT_READ, 1000, &generation), 1); + CHECK_INT(wait_for(sv[0], EVENT_IN, 1000, &generation), 1); CHECK_INT(generation, 100); - CHECK_INT(wait_for(other[0], EVENT_READ, 1000, &generation), 1); + CHECK_INT(wait_for(other[0], EVENT_IN, 1000, &generation), 1); CHECK_INT(generation, 200); test_case("and re-registering one changes only its own"); - CHECK_INT(event_modify(sv[0], EVENT_READ, 101), 0); - CHECK_INT(wait_for(sv[0], EVENT_READ, 1000, &generation), 1); + CHECK_INT(event_modify(sv[0], EVENT_IN, 101), 0); + CHECK_INT(wait_for(sv[0], EVENT_IN, 1000, &generation), 1); CHECK_INT(generation, 101); - CHECK_INT(wait_for(other[0], EVENT_READ, 1000, &generation), 1); + CHECK_INT(wait_for(other[0], EVENT_IN, 1000, &generation), 1); CHECK_INT(generation, 200); event_del(sv[0]); @@ -162,23 +162,23 @@ static void case_delete_from_the_middle(void) { test_case("deleting one of three leaves the others reported correctly"); for (i = 0; i < 3; ++i) { CHECK_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, pair[i]), 0); - CHECK_INT(event_add(pair[i][0], EVENT_READ, (uint32_t)(10 + i)), 0); + CHECK_INT(event_add(pair[i][0], EVENT_IN, (uint32_t)(10 + i)), 0); } CHECK_INT(event_del(pair[1][0]), 0); for (i = 0; i < 3; i += 2) { CHECK_INT(write(pair[i][1], "x", 1), 1); - CHECK_INT(wait_for(pair[i][0], EVENT_READ, 1000, &generation), 1); + CHECK_INT(wait_for(pair[i][0], EVENT_IN, 1000, &generation), 1); CHECK_INT(generation, 10 + i); } test_case("and the survivors can still be changed and removed"); - CHECK_INT(event_modify(pair[2][0], EVENT_READ, 99), 0); - CHECK_INT(wait_for(pair[2][0], EVENT_READ, 1000, &generation), 1); + CHECK_INT(event_modify(pair[2][0], EVENT_IN, 99), 0); + CHECK_INT(wait_for(pair[2][0], EVENT_IN, 1000, &generation), 1); CHECK_INT(generation, 99); CHECK_INT(event_del(pair[0][0]), 0); CHECK_INT(event_del(pair[2][0]), 0); - CHECK_INT(wait_for(pair[2][0], EVENT_READ, 50, NULL), 0); + CHECK_INT(wait_for(pair[2][0], EVENT_IN, 50, NULL), 0); for (i = 0; i < 3; ++i) close(pair[i][0]), close(pair[i][1]); @@ -201,7 +201,7 @@ static void case_timeout(void) { static void case_unknown_descriptor(void) { test_case("changing or removing one that was never added is refused"); - CHECK_INT(event_modify(4096, EVENT_READ, 1), -1); + CHECK_INT(event_modify(4096, EVENT_IN, 1), -1); CHECK_INT(event_del(4096), -1); } -- cgit v1.3