mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-06 18:04:03 +00:00
nhrpd: convert zbuf queue to DLIST
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
parent
b4f3d41bfd
commit
f9aa07b1a8
21
nhrpd/zbuf.c
21
nhrpd/zbuf.c
@ -164,35 +164,33 @@ void *zbuf_may_pull_until(struct zbuf *zb, const char *sep, struct zbuf *msg)
|
|||||||
void zbufq_init(struct zbuf_queue *zbq)
|
void zbufq_init(struct zbuf_queue *zbq)
|
||||||
{
|
{
|
||||||
*zbq = (struct zbuf_queue){
|
*zbq = (struct zbuf_queue){
|
||||||
.queue_head = LIST_INITIALIZER(zbq->queue_head),
|
.queue_head = INIT_DLIST(zbq->queue_head),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void zbufq_reset(struct zbuf_queue *zbq)
|
void zbufq_reset(struct zbuf_queue *zbq)
|
||||||
{
|
{
|
||||||
struct zbuf *buf, *bufn;
|
struct zbuf *buf;
|
||||||
|
|
||||||
list_for_each_entry_safe(buf, bufn, &zbq->queue_head, queue_list)
|
frr_each_safe (zbuf_queue, &zbq->queue_head, buf) {
|
||||||
{
|
zbuf_queue_del(&zbq->queue_head, buf);
|
||||||
list_del(&buf->queue_list);
|
|
||||||
zbuf_free(buf);
|
zbuf_free(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void zbufq_queue(struct zbuf_queue *zbq, struct zbuf *zb)
|
void zbufq_queue(struct zbuf_queue *zbq, struct zbuf *zb)
|
||||||
{
|
{
|
||||||
list_add_tail(&zb->queue_list, &zbq->queue_head);
|
zbuf_queue_add_tail(&zbq->queue_head, zb);
|
||||||
}
|
}
|
||||||
|
|
||||||
int zbufq_write(struct zbuf_queue *zbq, int fd)
|
int zbufq_write(struct zbuf_queue *zbq, int fd)
|
||||||
{
|
{
|
||||||
struct iovec iov[16];
|
struct iovec iov[16];
|
||||||
struct zbuf *zb, *zbn;
|
struct zbuf *zb;
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
size_t iovcnt = 0;
|
size_t iovcnt = 0;
|
||||||
|
|
||||||
list_for_each_entry_safe(zb, zbn, &zbq->queue_head, queue_list)
|
frr_each_safe (zbuf_queue, &zbq->queue_head, zb) {
|
||||||
{
|
|
||||||
iov[iovcnt++] = (struct iovec){
|
iov[iovcnt++] = (struct iovec){
|
||||||
.iov_base = zb->head, .iov_len = zbuf_used(zb),
|
.iov_base = zb->head, .iov_len = zbuf_used(zb),
|
||||||
};
|
};
|
||||||
@ -204,15 +202,14 @@ int zbufq_write(struct zbuf_queue *zbq, int fd)
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
list_for_each_entry_safe(zb, zbn, &zbq->queue_head, queue_list)
|
frr_each_safe (zbuf_queue, &zbq->queue_head, zb) {
|
||||||
{
|
|
||||||
if (r < (ssize_t)zbuf_used(zb)) {
|
if (r < (ssize_t)zbuf_used(zb)) {
|
||||||
zb->head += r;
|
zb->head += r;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
r -= zbuf_used(zb);
|
r -= zbuf_used(zb);
|
||||||
list_del(&zb->queue_list);
|
zbuf_queue_del(&zbq->queue_head, zb);
|
||||||
zbuf_free(zb);
|
zbuf_free(zb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
nhrpd/zbuf.h
10
nhrpd/zbuf.h
@ -15,18 +15,22 @@
|
|||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "list.h"
|
#include "typesafe.h"
|
||||||
|
|
||||||
|
PREDECL_DLIST(zbuf_queue);
|
||||||
|
|
||||||
struct zbuf {
|
struct zbuf {
|
||||||
struct list_head queue_list;
|
struct zbuf_queue_item queue_entry;
|
||||||
unsigned allocated : 1;
|
unsigned allocated : 1;
|
||||||
unsigned error : 1;
|
unsigned error : 1;
|
||||||
uint8_t *buf, *end;
|
uint8_t *buf, *end;
|
||||||
uint8_t *head, *tail;
|
uint8_t *head, *tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DECLARE_DLIST(zbuf_queue, struct zbuf, queue_entry);
|
||||||
|
|
||||||
struct zbuf_queue {
|
struct zbuf_queue {
|
||||||
struct list_head queue_head;
|
struct zbuf_queue_head queue_head;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct zbuf *zbuf_alloc(size_t size);
|
struct zbuf *zbuf_alloc(size_t size);
|
||||||
|
Loading…
Reference in New Issue
Block a user