diff options
Diffstat (limited to 'link')
| -rw-r--r-- | link/link-protocol.c | 6 | ||||
| -rw-r--r-- | link/link-protocol.h | 2 | ||||
| -rw-r--r-- | link/link.c | 7 | ||||
| -rw-r--r-- | link/link.h | 2 |
4 files changed, 16 insertions, 1 deletions
diff --git a/link/link-protocol.c b/link/link-protocol.c index 7940d90..12f9a24 100644 --- a/link/link-protocol.c +++ b/link/link-protocol.c @@ -251,7 +251,7 @@ struct PureLinkSender { /* Their bytes, one after another as queued (a record's never cut by the * ring's end): taken back in order as they are stored. */ unsigned char *ring; - size_t ring_capacity; + size_t ring_capacity, held; /* held: the bytes of the records, together */ uint64_t queued, stored; /* the last queued; saved by the receiver */ uint64_t run, next_pn, in_run; PureAead *out, *in; /* made once the receiver's key is known */ @@ -461,6 +461,7 @@ bool pure_link_sender_queue(PureLinkSender *l, uint64_t seq, const unsigned char if (!ok) return false; *record_at(l, l->count++) = r; l->queued = seq; + l->held += size; return true; } @@ -699,6 +700,7 @@ static void on_stored(PureLinkSender *l, const unsigned char *p, size_t size, ui Record *r = record_at(l, 0); for (uint32_t i = 0; i < r->parts; ++i) l->received -= part_of(r, i)->state == RECEIVED; free(r->more); /* its bytes go back with the ring's head */ + l->held -= r->size; l->head = (l->head + 1) & (l->capacity - 1); --l->count; } @@ -1190,6 +1192,8 @@ size_t pure_link_sender_datagram(const PureLinkSender *l) { return l->datagram; uint64_t pure_link_sender_stored(const PureLinkSender *l) { return l->stored; } +size_t pure_link_sender_held(const PureLinkSender *l) { return l->held; } + void pure_link_sender_counts(const PureLinkSender *l, PureLinkCounts *out) { *out = l->counts; out->stored = l->stored; diff --git a/link/link-protocol.h b/link/link-protocol.h index 96085c6..e4d3080 100644 --- a/link/link-protocol.h +++ b/link/link-protocol.h @@ -196,6 +196,8 @@ void pure_link_sender_epochs(PureLinkSender *, uint64_t every_ns, uint64_t bytes /* The last number queued; the last the receiver stored. */ uint64_t pure_link_sender_queued(const PureLinkSender *); uint64_t pure_link_sender_stored(const PureLinkSender *); +/* The bytes of the sends queued and not yet stored. */ +size_t pure_link_sender_held(const PureLinkSender *); void pure_link_sender_counts(const PureLinkSender *, PureLinkCounts *); void pure_link_sender_free(PureLinkSender *); diff --git a/link/link.c b/link/link.c index 37a5a2a..ad9376c 100644 --- a/link/link.c +++ b/link/link.c @@ -210,6 +210,13 @@ uint64_t pure_link_delivered(PureLink *l) { return stored; } +size_t pure_link_held(PureLink *l) { + pthread_mutex_lock(&l->lock); + size_t held = pure_link_sender_held(l->sender); + pthread_mutex_unlock(&l->lock); + return held; +} + static void take_answers(PureLink *l, uint64_t now) { for (unsigned rounds = 0, n = TAKE; rounds < 4 && n == TAKE; ++rounds) { n = (unsigned)take_datagrams(l->fd, l->taking); diff --git a/link/link.h b/link/link.h index 3390a82..64846ce 100644 --- a/link/link.h +++ b/link/link.h @@ -22,6 +22,8 @@ bool pure_link_queue(PureLink *, uint64_t seq, const unsigned char *bytes, size_ uint64_t pure_link_queued(PureLink *); /* The last number the receiver saved; any thread. */ uint64_t pure_link_delivered(PureLink *); +/* The bytes of the sends queued and not yet saved; any thread. */ +size_t pure_link_held(PureLink *); /* Packets go in bursts with UDP GSO where the system has it (at first); * off, each in a call of its own: for a path whose queues take a burst as * one packet (netem does). Before pure_link_start. */ |
