Skip to content

Commit 2e9e4da

Browse files
all rx functions implemented except port push
1 parent 2480c38 commit 2e9e4da

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

.idea/dictionaries/project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libudpard/udpard.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,16 @@ bool udpard_rx_new(udpard_rx_t* const self,
15531553
return ok;
15541554
}
15551555

1556+
void udpard_rx_free(udpard_rx_t* const self)
1557+
{
1558+
if (self != NULL) {
1559+
while (self->list_session_by_animation.tail != NULL) {
1560+
udpard_rx_port_free(self,
1561+
LIST_TAIL(self->list_session_by_animation, rx_session_t, list_by_animation)->owner);
1562+
}
1563+
}
1564+
}
1565+
15561566
void udpard_rx_poll(udpard_rx_t* const self, const udpard_us_t now)
15571567
{
15581568
UDPARD_ASSERT(!self->p2p_port.invoked);
@@ -1595,6 +1605,7 @@ bool udpard_rx_port_new(udpard_rx_port_t* const self,
15951605
self->reordering_window = reordering_window;
15961606
self->memory = memory;
15971607
self->index_session_by_remote_uid = NULL;
1608+
self->user = NULL;
15981609
self->invoked = false;
15991610
}
16001611
return ok;

libudpard/udpard.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -478,12 +478,10 @@ uint32_t udpard_tx_p2p(udpard_tx_t* const self,
478478
/// The returned item (if any) is guaranteed to be non-expired (deadline>=now).
479479
udpard_tx_item_t* udpard_tx_peek(udpard_tx_t* const self, const udpard_us_t now);
480480

481-
/// Transfers the ownership of the specified item to the application. The item does not necessarily need to be the
482-
/// top one -- it is safe to dequeue any item. The item is dequeued but not invalidated; it is the responsibility of
483-
/// the application to deallocate its memory later.
484-
/// The memory SHALL NOT be deallocated UNTIL this function is invoked (use udpard_tx_free()).
481+
/// Transfers the ownership of the specified item to the application. The item does not have to be the top one.
482+
/// The item is dequeued but not invalidated; the application must deallocate its memory later; see udpard_tx_free().
483+
/// The memory SHALL NOT be deallocated UNTIL this function is invoked.
485484
/// If any of the arguments are NULL, the function has no effect.
486-
/// This function does not invoke the dynamic memory manager.
487485
void udpard_tx_pop(udpard_tx_t* const self, udpard_tx_item_t* const item);
488486

489487
/// This is a simple helper that frees the memory allocated for the item and its payload.
@@ -516,7 +514,7 @@ typedef struct udpard_rx_memory_resources_t
516514
/// -----------------------------------------−-------------------------------------------------------------------------
517515
/// ORDERED Strictly increasing transfer-ID May delay transfers Non-negative number of microseconds
518516
/// UNORDERED Unique transfer-ID Ordering not guaranteed UDPARD_REORDERING_WINDOW_UNORDERED
519-
/// STATELESS Constant time, constant memory Single-frame only, duplicates UDPARD_REORDERING_WINDOW_STATELESS
517+
/// STATELESS Constant time, constant memory 1-frame only, dups, no responses UDPARD_REORDERING_WINDOW_STATELESS
520518
///
521519
/// If not sure, choose the ORDERED mode with a ~5 ms reordering window for all topics except for request-response
522520
/// RPC-style, in which case choose UNORDERED. The STATELESS mode is chiefly intended just for the heartbeat topic.
@@ -616,6 +614,9 @@ typedef struct udpard_rx_port_t
616614
/// which is easy to implement since each port gets a dedicated set of memory resources.
617615
udpard_tree_t* index_session_by_remote_uid;
618616

617+
/// Opaque pointer for the application use only. Not accessed by the library.
618+
void* user;
619+
619620
/// Do not access. This is used to prevent accidental reentry from within the callbacks.
620621
bool invoked;
621622
} udpard_rx_port_t;
@@ -705,11 +706,10 @@ typedef struct udpard_rx_t
705706

706707
/// The extent of the P2P port is set to SIZE_MAX by default (no truncation at all).
707708
/// The application can alter it via udpard_rx_t::p2p_port.extent at any moment if needed; it takes effect immediately
708-
/// but may in some cases cause in-progress transfers to be lost if increased mid-transfer.
709-
///
710-
/// To free a udpard_rx_t instance, the application must simply free all its ports using udpard_rx_port_free().
711-
/// The RX instance will be safe to discard afterward.
712-
///
709+
/// but may in some cases cause in-progress transfers to be lost if increased mid-transfer,
710+
/// so it is best to do it once after initialization.
711+
/// The application does not need to initialize the P2P port itself; it is initialized automatically.
712+
/// The application must push the datagrams arriving to its P2P sockets into this port using udpard_rx_port_push().
713713
/// True on success, false if any of the arguments are invalid.
714714
bool udpard_rx_new(udpard_rx_t* const self,
715715
const uint64_t local_uid,
@@ -718,6 +718,13 @@ bool udpard_rx_new(udpard_rx_t* const self,
718718
const udpard_rx_on_collision_t on_collision,
719719
const udpard_rx_on_ack_mandate_t on_ack_mandate);
720720

721+
/// Returns all memory allocated for the entire RX stack, including all ports, sessions, slots, fragments, etc.
722+
/// It is safe to invoke this at any time, but the instance and its ports shall not be used again unless
723+
/// re-initialized. Only memory that is allocated by the library is returned; the ports and the RX instance
724+
/// themselves are not freed.
725+
/// The function has no effect if the argument is NULL.
726+
void udpard_rx_free(udpard_rx_t* const self);
727+
721728
/// Must be invoked at least every few milliseconds (more often is fine) to purge timed-out sessions and eject
722729
/// received transfers when the reordering window expires. If this is invoked simultaneously with rx subscription
723730
/// reception, then this function should ideally be invoked after the reception handling.

0 commit comments

Comments
 (0)