Skip to content

Commit 689bc35

Browse files
remove dedicated cancel function for p2p; use udpard_tx_cancel() for everything
1 parent 8a4c474 commit 689bc35

3 files changed

Lines changed: 1 addition & 101 deletions

File tree

libudpard/udpard.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,11 +1401,6 @@ bool udpard_tx_cancel(udpard_tx_t* const self, const uint64_t topic_hash, const
14011401
return cancelled;
14021402
}
14031403

1404-
bool udpard_tx_cancel_p2p(udpard_tx_t* const self, const uint64_t destination_uid, const uint64_t transfer_id)
1405-
{
1406-
return udpard_tx_cancel(self, destination_uid, transfer_id);
1407-
}
1408-
14091404
size_t udpard_tx_cancel_all(udpard_tx_t* const self, const uint64_t topic_hash)
14101405
{
14111406
size_t count = 0;

libudpard/udpard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,14 @@ bool udpard_tx_push_p2p(udpard_tx_t* const self,
551551
void udpard_tx_poll(udpard_tx_t* const self, const udpard_us_t now, const uint16_t iface_bitmap);
552552

553553
/// Cancel a previously enqueued transfer.
554+
/// To cancel a P2P transfer, pass the destination node's UID as the topic_hash.
554555
/// If provided, the feedback callback will be invoked with success==false.
555556
/// Not safe to call from the eject() callback.
556557
/// Returns true if a transfer was found and cancelled, false if no such transfer was found.
557558
/// The complexity is O(log t + f), where t is the number of enqueued transfers,
558559
/// and f is the number of frames in the transfer.
559560
/// The function will free the memory associated with the transfer.
560561
bool udpard_tx_cancel(udpard_tx_t* const self, const uint64_t topic_hash, const uint64_t transfer_id);
561-
bool udpard_tx_cancel_p2p(udpard_tx_t* const self, const uint64_t destination_uid, const uint64_t transfer_id);
562562

563563
/// Like udpard_tx_cancel(), but cancels all transfers matching the given topic hash.
564564
/// Returns the number of matched transfers.

tests/src/test_intrusive_tx.c

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,100 +1007,6 @@ static void test_tx_cancel_all(void)
10071007
instrumented_allocator_reset(&alloc);
10081008
}
10091009

1010-
// Cancels P2P transfers and reports outcome.
1011-
static void test_tx_cancel_p2p(void)
1012-
{
1013-
// NULL self returns false.
1014-
TEST_ASSERT_FALSE(udpard_tx_cancel_p2p(NULL, 0, 0));
1015-
1016-
instrumented_allocator_t alloc = { 0 };
1017-
instrumented_allocator_new(&alloc);
1018-
udpard_tx_mem_resources_t mem = { .transfer = instrumented_allocator_make_resource(&alloc) };
1019-
for (size_t i = 0; i < UDPARD_IFACE_COUNT_MAX; i++) {
1020-
mem.payload[i] = instrumented_allocator_make_resource(&alloc);
1021-
}
1022-
1023-
udpard_tx_t tx = { 0 };
1024-
feedback_state_t fstate = { 0 };
1025-
eject_state_t eject = { .count = 0, .allow = false };
1026-
udpard_tx_vtable_t vt = { .eject_subject = eject_subject_with_flag, .eject_p2p = eject_p2p_with_flag };
1027-
TEST_ASSERT_TRUE(udpard_tx_new(&tx, 50U, 100U, 8U, mem, &vt));
1028-
tx.user = &eject;
1029-
1030-
// Push a P2P transfer with feedback (reliable), using out_transfer_id.
1031-
const udpard_remote_t remote = { .uid = 999, .endpoints = { make_ep(10), make_ep(20) } };
1032-
uint64_t out_tid = 0;
1033-
TEST_ASSERT_TRUE(udpard_tx_push_p2p(&tx,
1034-
0,
1035-
1000,
1036-
udpard_prio_fast,
1037-
remote,
1038-
make_scattered(NULL, 0),
1039-
record_feedback,
1040-
make_user_context(&fstate),
1041-
&out_tid));
1042-
// Verify out_transfer_id matches internal counter.
1043-
TEST_ASSERT_EQUAL_UINT64(100, out_tid); // initial p2p_transfer_id was 100
1044-
// P2P transfers are indexed by (remote.uid, internal_transfer_id).
1045-
TEST_ASSERT_NOT_NULL(tx_transfer_find(&tx, remote.uid, out_tid));
1046-
1047-
// Cancel using the returned transfer_id from out_transfer_id.
1048-
TEST_ASSERT_TRUE(udpard_tx_cancel_p2p(&tx, remote.uid, out_tid));
1049-
TEST_ASSERT_NULL(tx_transfer_find(&tx, remote.uid, out_tid));
1050-
TEST_ASSERT_EQUAL_size_t(1, fstate.count);
1051-
TEST_ASSERT_EQUAL_UINT32(0, fstate.last.acknowledgements);
1052-
// Cancelling again returns false (already cancelled).
1053-
TEST_ASSERT_FALSE(udpard_tx_cancel_p2p(&tx, remote.uid, out_tid));
1054-
1055-
// Cancelling with wrong destination_uid returns false.
1056-
fstate.count = 0;
1057-
uint64_t out_tid2 = 0;
1058-
TEST_ASSERT_TRUE(udpard_tx_push_p2p(&tx,
1059-
0,
1060-
1000,
1061-
udpard_prio_fast,
1062-
remote,
1063-
make_scattered(NULL, 0),
1064-
record_feedback,
1065-
make_user_context(&fstate),
1066-
&out_tid2));
1067-
TEST_ASSERT_FALSE(udpard_tx_cancel_p2p(&tx, 888, out_tid2)); // wrong destination
1068-
TEST_ASSERT_NOT_NULL(tx_transfer_find(&tx, remote.uid, out_tid2));
1069-
TEST_ASSERT_EQUAL_size_t(0, fstate.count); // feedback not invoked
1070-
1071-
// Cancelling with wrong transfer_id returns false.
1072-
TEST_ASSERT_FALSE(udpard_tx_cancel_p2p(&tx, remote.uid, 12345)); // wrong transfer_id
1073-
TEST_ASSERT_NOT_NULL(tx_transfer_find(&tx, remote.uid, out_tid2));
1074-
1075-
// Cancel with correct parameters works.
1076-
TEST_ASSERT_TRUE(udpard_tx_cancel_p2p(&tx, remote.uid, out_tid2));
1077-
TEST_ASSERT_NULL(tx_transfer_find(&tx, remote.uid, out_tid2));
1078-
TEST_ASSERT_EQUAL_size_t(1, fstate.count);
1079-
1080-
// Best-effort P2P transfer cancels quietly (no feedback); using NULL for out_transfer_id.
1081-
fstate.count = 0;
1082-
uint64_t out_tid3 = 0;
1083-
TEST_ASSERT_TRUE(udpard_tx_push_p2p(
1084-
&tx, 0, 1000, udpard_prio_nominal, remote, make_scattered(NULL, 0), NULL, UDPARD_USER_CONTEXT_NULL, &out_tid3));
1085-
TEST_ASSERT_TRUE(udpard_tx_cancel_p2p(&tx, remote.uid, out_tid3));
1086-
TEST_ASSERT_EQUAL_size_t(0, fstate.count); // no feedback for best-effort
1087-
1088-
// Test cancel_all with P2P transfers (using destination_uid as topic_hash).
1089-
// Pass NULL for out_transfer_id to verify optional behavior.
1090-
TEST_ASSERT_TRUE(udpard_tx_push_p2p(
1091-
&tx, 0, 1000, udpard_prio_fast, remote, make_scattered(NULL, 0), NULL, UDPARD_USER_CONTEXT_NULL, NULL));
1092-
TEST_ASSERT_TRUE(udpard_tx_push_p2p(
1093-
&tx, 0, 1000, udpard_prio_fast, remote, make_scattered(NULL, 0), NULL, UDPARD_USER_CONTEXT_NULL, NULL));
1094-
const udpard_remote_t other_remote = { .uid = 777, .endpoints = { make_ep(30) } };
1095-
TEST_ASSERT_TRUE(udpard_tx_push_p2p(
1096-
&tx, 0, 1000, udpard_prio_fast, other_remote, make_scattered(NULL, 0), NULL, UDPARD_USER_CONTEXT_NULL, NULL));
1097-
TEST_ASSERT_EQUAL_size_t(2, udpard_tx_cancel_all(&tx, remote.uid));
1098-
TEST_ASSERT_EQUAL_size_t(1, udpard_tx_cancel_all(&tx, other_remote.uid));
1099-
1100-
udpard_tx_free(&tx);
1101-
instrumented_allocator_reset(&alloc);
1102-
}
1103-
11041010
static void test_tx_spool_deduplication(void)
11051011
{
11061012
instrumented_allocator_t alloc_a = { 0 };
@@ -1311,7 +1217,6 @@ int main(void)
13111217
RUN_TEST(test_tx_stage_if_via_tx_push);
13121218
RUN_TEST(test_tx_stage_if_short_deadline);
13131219
RUN_TEST(test_tx_cancel);
1314-
RUN_TEST(test_tx_cancel_p2p);
13151220
RUN_TEST(test_tx_cancel_all);
13161221
RUN_TEST(test_tx_spool_deduplication);
13171222
RUN_TEST(test_tx_eject_only_from_poll);

0 commit comments

Comments
 (0)